Skip to content

Advanced navigation patterns #767

@agundermann

Description

@agundermann

I think it would be great to offer some advanced navigation functionality such as:

  • canGoBack()
  • canGo(n)
  • go(n) // n positive or negative, like with history.go(n)
  • canGoBackTo(name, params, query)
  • goBackTo(name, params, query) // goes back to when the route was last active
  • state.historyId // e.g. for caching stuff based on current history entry like form data, or choosing animations by comparing to previous state

This could also be very useful for implementing up navigation in Android.

While this seems trivial to implement for in memory locations (for react-native), in my opionion it would also be great to have this for web apps. I've actually played around with this in the past, and I think it might actually be possible to make this happen for HistoryLocation by managing a counter within the history state object. I don't think it's possible with HashLocation or RefreshLocation though.

Implementation-wise there's also the problem of how to provide persistency (hitting refresh button, closing browser), but I first wanted to hear what you think about this API.

On a related note, the current goBack() doesn't play well when using browser navigation. With this kind of approach, it should be possible to make it work reliably.

Related #765

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions