简体   繁体   中英

What should happen when clicking the back button in an angular2 routing app?

I have implemented the angular2 routing concept with modules in my web application. Everything works fine.

The problem is I'm not sure what should happen upon clicking the browser back button which sends to the previous page normally. In my situation I see that by default the browser back button sends my app to the previous routing path and so on until it reaches the initial-home page.

Should the back button behave in such way on SPA applications or should it send the user to the home page directly?

Should the back button behave in such way on SPA applications or should it send the user to the home page directly?

The fact that your application is a SPA should be transparent to the user . This is the whole purpose of using a router: that the current state of the SPA can at least partially be read from the route. It also enables sharing the links or saving them as bookmarks. For more advanced usages, it also enables server-side rendering, which then leads to possibility for search engine optimizations.

That said, this is what it should be like and what the users probably expect. Your application can do whatever it likes . If you want back button to go to the home page instead of to the previously visited page, make sure that you do not push anything to the browser's history, and instead just replace it.

Note, however, that you cannot imitate this if the user has never landed on the home page. If she comes from a Google search result, or from a link that friend has sent via e-mail, for example, website.example/foo , and she navigates to website.example/bar from there, you have no way to imitate that the back button should take her to website.example . This would be a security issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM