简体   繁体   中英

History.js URL without trailing slash doesn't work correctly

I'm using the History.js for URL changes without reloading. This is used on a website with product filters, where the filters are placed in the URL so the URL can be shared with the active filters.

The URL's of the website don't end on a trailing slash, so a valid URL for the site is: www.mysite.com/products .

This URL would show you a list with all products an you are ably to apply filters. Applying a filters should change the URL to:

www.mysite.com/products/?filter1=2,4,6&filter2=4

This works in FireFox, Chrome, IE11. In IE9 however, it fails on the trailing slash. The URL in IE9 is change to:

www.mysite.com/products#products?filter1=2,4,6&filter2=4

It seems that it sees product as a parameter, in stead of a part of the URL. If I manually add a trailing slash behind the URL, it works fine in IE9.

Base URL: www.mysite.com/products/ will be www.mysite.com/products/?filter1=2,4,6&filter2=4 when using the history.js, even in IE9.

So summary: Adding a trailing slash at the end of the base URL fixes the problem. But I don't want to add that last trailing slash, the history.js should do that. How would that be accomplished?

EDIT

I think the problem is in this part of the code, th

var basePageUrl = (History.getLocationHref()).replace(/[#\?].*/,'').replace(/[^\/]+$/,function(part,index,string){
  return (/[^\/]$/).test(part) ? '' : part;
}).replace(/\/+$/,'')+'/';

This script turns this baseURL: www.mysite.com/products into: www.mysite.com

I'm not that strong in regex, so actually have no idea what the regex does in this example.

in the History.getPageUrl function, I've added this line

//Yoni's hack to not have trailing slash
        if (pageUrl.substr(pageUrl.length - 1, 1) == '/') {
            pageUrl = pageUrl.substr(0, pageUrl.length - 1);
        }

just before the

return pageUrl;

In Symfony 2 we are not using trailing slash, so there is never use of it, and it's then a good condition, if you need both possibilities, you have to handle it in another way probably

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