Missing navigation history/back functionality

未关闭
#539 0 条评论 21 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
28/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
react, typescript
领域
frontend

调研方向

未指定文件或测试。首先查看 wouter 现有的 router 和导航入口,然后将其与提议的 useHistory 和 navigateBack API 进行比较。当项目范围已确定,并且已记录前一路由导航、回退处理和历史状态管理的行为时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Problem

Currently, wouter doesn't provide a built-in way to navigate back to the previous page or access navigation history. This forces developers to implement workarounds like:

  • Using window.history.back() directly (which may cause page reloads)
  • Implementing custom state management with sessionStorage/localStorage
  • Creating complex navigation state tracking systems

Use Case

In a typical SPA, users expect the back button to work intuitively:

  • From a product page back to the store page
  • From an order details page back to the orders list
  • From any nested page back to its parent

Proposed Solution

It would be great if wouter could provide:

  1. A useHistory hook that gives access to navigation history
  2. A navigateBack() function that safely goes to the previous route
  3. History state management that works seamlessly with the router

Current Workaround

const handleBack = useCallback(() => {
  if (window.history.length > 1) {
    window.history.back();
  } else {
    navigate('/fallback-route');
  }
}, [navigate]);

Questions

  • Is there a recommended way to handle back navigation in wouter?
  • Are there plans to add history management features?
  • Should we consider using a different router that has this functionality built-in?

This would significantly improve the developer experience and make wouter more competitive with other routing solutions.

主要语言
TypeScript
星标
7.9k
派生
193
平均合并
9 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

molefrog/wouter 的其他 Issue

查看 molefrog/wouter 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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