I have a goback btn in spa ,then router.history can't goback, i want it go to another page(maybe not this web).
I want using history stack , or history stack length to fix it.
but i can't get the history stack.
This varies with the route system you use
In general you already have this information https://developer.mozilla.org/en-US/docs/Web/API/History_API
I do not know if it would be interesting to put this inside the vue-router.
@vinicius73 sometimes the window.history.length down't work well in spa,the value is not real in spa.
@EDiaos yes, but vue-router is fully based in this object
https://github.com/vuejs/vue-router/blob/v2.0.3/src/history/hash.js
https://github.com/vuejs/vue-router/blob/v2.0.3/src/history/html5.js
Hi, thanks for filling this issue. Clicking browser back will always go one step back in the history record (which isn't exposed by browser API), so what you're proposing isn't possible.
I've found one package called history that uses createMemoryHistory method to expose the history.entries prop for the browser history stack's inspection.
I'm wondering whether this feature could be integrated with the vue-router.
@shuaibird I agree, the History package is very powerful... at first i actually thought that vue-router does that. Howbeit, this is the missing part in vue-router... integrating it can actually make it even more useful. Consider this. the problem I was having was trying to change the behaviour of a back button depending on where it is going. The user may have come to the current component through many ways. If they are going to back off to a certain component, i want the back button logic to decide what to do before taking them there. I can only do that if i can tell the location they are going back to. Hence the need for stack inspection, which vue-router doesn't provide.
Just stumbled on this one as well. In my case, I have a welcome / loading screen and leaving it replace the URL to the actual first screen. Using guards, I can just check if the screen transition is the first one or not:
beforeRouteEnter (to, from, next) {
next(vm => {
vm.rootScreen = from.fullPath === '/'
})
}
That way, in my component methods, I can do all sort of fancy stuff based on that data, like specify handling of the back button.
Thought I would share this, hoping it helps anybody.
beforeRouteEnter nor beforeRouteupdate work not always.
Most helpful comment
Just stumbled on this one as well. In my case, I have a welcome / loading screen and leaving it replace the URL to the actual first screen. Using guards, I can just check if the screen transition is the first one or not:
That way, in my component methods, I can do all sort of fancy stuff based on that data, like specify handling of the back button.
Thought I would share this, hoping it helps anybody.