history.js icon indicating copy to clipboard operation
history.js copied to clipboard

Trailing slash always appended to URL before state parameters

Open jasonhill opened this issue 13 years ago • 27 comments

Hi,

The standard for our site is to remove trailing slashes in URLs with a permanent redirect. However, the History control seems to be always appending a slash before the state parameters. Shouldn't it just be looking at the current URL and appending the state parameters rather than always assuming a trailing slash?

Is there any way to control that behaviour?

Thanks,

Jason

jasonhill avatar Jan 12 '12 23:01 jasonhill

Having the same problem. This broke my rails app routes because of the "unix" style paths

longlostnick avatar Mar 12 '12 15:03 longlostnick

I ended up editing the js to stop it appending the trailing slash.

jasonhill avatar Mar 12 '12 22:03 jasonhill

i tried that too, but ultimately ended up going w bbq.js because all i needed was the basics anyway. didnt really look too closely but maybe bbq can do all the stuff this does anyway. worth looking at if youre still having trouble.

longlostnick avatar Mar 12 '12 23:03 longlostnick

I think I looked at bbq but it just uses the hash rather than querystring right?

jasonhill avatar Mar 12 '12 23:03 jasonhill

Yep, I believe that was the difference.

longlostnick avatar Mar 12 '12 23:03 longlostnick

If your page URL is http://example.com/page, try calling pushState() with a url like "page?parameter".

AntonKast avatar May 11 '12 03:05 AntonKast

+1 @AntonKast - This is the solution, solved it for me.

tomthetree avatar Jan 17 '13 17:01 tomthetree

+1 @AntonKast

joeferraro avatar May 28 '13 10:05 joeferraro

@AntonKast the solution works, but we should get this changed so it doesn't keep adding it on. As @jasonhill said we should be able to control this currently doesn't mimic the history api

AaronLayton avatar Jun 25 '13 13:06 AaronLayton

I agree with @AaronLayton

matteopoile avatar Nov 12 '13 18:11 matteopoile

Any news on this issue?

When I use query to define new location it adds trailing slash which doesn't make sense. There could be an option to enable/disable this behavior.

What do you think?

mhlavac avatar Feb 05 '14 09:02 mhlavac

+1

AaronLayton avatar Feb 05 '14 09:02 AaronLayton

+1

verdet23 avatar Mar 04 '14 08:03 verdet23

+1

pensiero avatar Mar 23 '14 19:03 pensiero

+1

jwynveen avatar Apr 15 '14 13:04 jwynveen

+1

MiguelRipoll23 avatar May 10 '14 23:05 MiguelRipoll23

+1

michelkusters avatar May 15 '14 12:05 michelkusters

I forgot to say that it only happens to me when domain is localhost.

MiguelRipoll23 avatar May 15 '14 12:05 MiguelRipoll23

This piece of code might be useful for some.

var href = $(this).prop("href");
History.pushState(null, null, href);

michelkusters avatar Jun 05 '14 11:06 michelkusters

+1

juliosantos avatar Aug 18 '14 21:08 juliosantos

@mhlavac :+1:

jenkek avatar Oct 02 '14 04:10 jenkek

+1

aSchimp avatar Nov 30 '15 23:11 aSchimp

2017 now passing...

ProPuke avatar Nov 05 '17 23:11 ProPuke

2019 now passing...

tristanjthompson avatar May 16 '19 08:05 tristanjthompson

Is this issue still a problem in 2019? Unless we are stuck supporting older, non-evergreen browsers etc.

AaronLayton avatar May 18 '19 10:05 AaronLayton

Instead change the logic where trialling '/' is invalid

Ex. In case there is request parameters too - https://www.xxxx.xxx/customer/?city=delhi // This is invalid case where /? should not together Best suitable solution would be replace trialling slash with .replace(//$/, '')

Code : else if ( firstChar === '?' ) { // Query URL fullUrl = History.getPageUrl().replace(//$/, '').replace(/[?#].*/,'')+url; }

After change: https://www.xxxx.xxx/customer?city=delhi

Manish-Solanki avatar Aug 06 '21 12:08 Manish-Solanki

I forgot to say that it only happens to me when domain is localhost.

Hi, did you find any workaround or solution for this? @MiguelRipoll23

Peter080202 avatar Dec 19 '22 11:12 Peter080202