Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Feature Request: Auto-generate unique ID for each route instance

未关闭
#4,371 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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)

  1. 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
  2. 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

  1. Automatically resolve cache conflicts for duplicate URLs
  2. Simplify state management for scroll positions, etc.
  3. 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

framework7io/framework7 的其他 Issue

查看 framework7io/framework7 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。