Feature Request: Auto-generate unique ID for each route instance
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- frontend
调研方向
先从 issue 中描述的 F7 Router 路由配置和 propsHistory 行为开始,然后查看 pull request #4375。完成的标准是:重复的 URL 路由实例会自动获得唯一的 ID,避免缓存冲突,并且报告中的 propsHistory 初始化和返回主页场景无需 hack 即可正常工作。
由索引模型根据 Issue 内容生成。
描述
Problem Description
Identical URL route instances cannot be distinguished, causing conflicts in cached states like scroll positions.
Desired Solution
The F7 Router should have built-in automatic unique ID generation for each route instance.
Suggested Implementation
// Route configuration support
routes: [{
path: '/page',
options: {
routeId: true // Auto-generate
// or
routeId: (route) => customIdGenerator(route)
}
}]
Current Workaround
// Currently only this hack works
nr.options.props = {
...props,
get rid() {
return `${Date.now()}_${Math.random().toString(36).slice(2)}`;
}
};
Additional Issues (specific to hack method)
-
propsHistory Initialization Defect (hack-specific)
- When using the hack method, the propsHistory array is empty on initial page load
- The default implementation might work normally, but the hack method disrupts the normal initialization flow
-
propsHistory Home Return Issue (hack-specific)
- When returning to the homepage using the hack method, propsHistory doesn't correctly record the homepage state
- The default implementation might have handled this correctly, but the hack method requires additional fixes
I've created a comprehensive PR that implements automatic route ID generation and fixes related history management issues. Here's the complete implementation:
https://github.com/framework7io/framework7/pull/4375
Explanation
These issues are specific to using the hack method (dynamically generating rid). In the default F7 Router implementation, these functions might already work normally. But to be compatible with the hack method, corresponding fix logic needs to be added to the code.
Expected Functionality
- Automatically resolve cache conflicts for duplicate URLs
- Simplify state management for scroll positions, etc.
- No manual handling of route IDs required
Technical Detail:
I use f7-store to create and restore cache based on this id, but encounter problems during deletion. Currently can only use code similar to:
const propsHistory = f7?.views?.main?.router?.propsHistory;
if (!propsHistory) return;
const originalPop = propsHistory.pop;
propsHistory.pop = function () {
const lastItem = this[this.length - 1];
const rid = lastItem?.rid;
const result = originalPop.apply(this, arguments);
return result;
};
Is there a better method? Or can this be optimized by adding the built-in route ID functionality to avoid developers having to use such hack methods?
- 主要语言
- JavaScript
- 星标
- 18.8k
- 派生
- 3.2k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
framework7io/framework7 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
framework7io/framework7#4365 · 1 条评论 ·
-
propsHistory 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
framework7io/framework7#4347 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 64/100
framework7io/framework7#4222 · 3 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
framework7io/framework7#4175 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
framework7io/framework7#3969 · 3 条评论 ·
查看 framework7io/framework7 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 78/100
Mintplex-Labs/anything-llm#6490 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
-
[quality] workflow-scripts guard reads test:unit:coverage as skipping the unit suite, blocking #632 未关闭agent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
难度 2/5 1-3 小时 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
area-clientside-dartpad
难度 2/5 1-3 小时 新手友好度 62/100