MaximVanhove / vue-router-back-button

Add a back button to your application
MIT License
66 stars 9 forks source link

Differentiate between going back and navigating to a route #2

Closed tomexx closed 6 years ago

tomexx commented 6 years ago

Hi, there is one problem that made this plugin unusable for me. I need to differentiate between going back using back button and navigating through pages.

Page A => Page B => Page A (now this.$routerHistory.hasForward() returns true, even when I have not used Back button)

tomexx commented 6 years ago

It's probably enough to introduce another check using _current and _history.length properties. I can create a PR later.

MaximVanhove commented 6 years ago

The problem is that the package listens on route enter and doesn't know if it went back by a button in the menu, the back button you added or the native back button.

tomexx commented 6 years ago

@MaximVanhove Yes... then that's no use in certain scenarios like I have... :/

MaximVanhove commented 6 years ago

Could you explain your scenarios? Maybe I can help.

tomexx commented 6 years ago

I need to differentiate these two scenarios:

1) Page A -> navigate to Page B -> navigate to Page A

2) Page A -> navigate to Page B -> back button (returning to Page A)

tomexx commented 6 years ago

Page A -> navigate to Page B -> navigate to Page A

the third step should be stored as a separate item in history array, then it would work as expected with all the methods I think

MaximVanhove commented 6 years ago

I think you can use the click event on the button and emit an event. What would you like to do if you click the back button?

tomexx commented 6 years ago

Well, that's tricky. I need to watch $route changes and then show or hide some component, depending on if user went back from certain route or came there from another place. Your package would solve this easily without handling events which would add complexity

MaximVanhove commented 6 years ago

I guess you could fork my repo and modify it so that it only writes history. Then use the click event on the button to go back to the last.