简体   繁体   中英

Angularjs - browser back button doesn't work

I am building an e-commerce site where the product page changes product variants by changing the select box which value reflects in the URL using window.location.href - so far, so good.

My URL has this format (the only thing that changes between variants is what goes after the hash) http://www.myecommerce.com/myproductpage#!#product=15647

The issue happens when clicking the native browser's back button, instead of returning back to the previous hash it reloads the same partial of page (the URL stays the same). The partial is loaded through post request.

I don't use any angular routing.

It would be hard for me to share a demo as the issue only happens after the AJAX request.

Try to change your URL style to something like that: ../myproductpage#/product/15647 You can use the angular router or the ui router (my preferred one) to do a correct routing. It seems that the browser inteprets the second hash tag as an anchor and doesn't navigate.

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