Skip to content

Missing navigation history/back functionality #539

@euhenriquecosta

Description

@euhenriquecosta

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions