angularjs: how to go back to previous page from a nested view when clicking back button of browser?

1.5k views Asked by At

I have two pages, index.html and tabs.html. tabs.html is a nested structure, it has a tabs component and every tab is bind to a state(tab1, tab2, tab3). When changing from index.html to tabs.html, the state change path will be: index -> tabs -> tab1. When you click other tabs, the state change path maybe: index -> tabs -> tab1 -> tab2. Now if you click the back button of the browser, you will just go back from tab2 to tab1, that means you are still in tabs.html. Now my question is, is there any good method to realize when clicking the back button of browser, I can go back to index.html not just the previous state?

1

There are 1 answers

1
Mahmoud On BEST ANSWER

Because back operation in browser works with URLs, you can remove url property in state definition for tab1, tab2 and tab3 states, and you have to link them just with ui-sref.

Now if you back in browser you will go to index.html