简体   繁体   中英

How to change address bar URL without redirecting the user (not using History API?)

I know it's a very common question around here. But I can't find answer that I'm looking for.

I need to achieve a very similar behaviour like Groupon.com does it. For instance, when you visit https://www.groupon.com/goods/all . On the left side you will see an " Interest " filtering widget and when you select one or more option, the page URL on the address bar will change to something like https://www.groupon.com/goods/all?interest=good-for-gifting .

In first place I thought that they are using the History API but they don't. Because when I check the history.length to see if it get increased, it always returns the same value.

Anyone knows how to do this?

It maybe because they use replaceState() method which does not add any entry to the history but replaces the current entry

https://developer.mozilla.org/en-US/docs/Web/API/History_API

Why don't you try URL Rewriting in htaccess or configuration files. You can refer below article. http://webrewrite.com/url-rewriting-htaccess/

Hope this is useful!

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