vuejs / router

🚦 The official router for Vue.js

Home Page:https://router.vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to check if a router has any pages to go back/forward to

Bertie2011 opened this issue · comments

What problem is this solving

I'm building an app where routers (and their views) are placed within virtual windows within the app. The windows have their own back/forwards buttons and it seems that I have no way of knowing if there are any pages to go back or forwards to.

Proposed solution

  • Exposing extra methods on router/history could be very useful (e.g. canGoBack, canGoForwards).
  • Another option would be adding some kind of indicator to what happens to history state in listener callbacks, so I can track a counter myself.
  • Or give access to the full browser history stack (which I guess is only an issue for the memory history), but a simple number or boolean would suffice for my use-case.

Describe alternatives you've considered

I looked in the API docs and couldn't find any useful methods/fields on the router/history.

This has been requested before. There is no native api to check for that but you can write to history.state after each navigation to create the behavior you want