molefrog / molefrog/wouter

Missing navigation history/back functionality

Open
#539 0 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.9k
Forks
190
Avg merge
12h 50m
Merged PRs (30d)
3

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by reviewing wouter's existing router and navigation entry points, then compare them with the proposed useHistory and navigateBack API. Done means the project has a decided scope and documented behavior for previous-route navigation, fallback handling, and history state management.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.