aurelia / router

A powerful client-side router.
MIT License
121 stars 115 forks source link

canDeactivate Hook Triggered Twice if the Destination Contains Unencoded Characters #630

Open robpal94 opened 5 years ago

robpal94 commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: The canDeactivate() hook is called twice whenever the destination route's fragment contains an unescaped character such as s space or letters like 'ä'.

If the hook is called the first time, the fragment of the passed NavigationInstruction is the unescaped string, which contains the raw special characters mentioned above.

After returning from canDeactivate(), the hook is called again. This time, the fragment contains the encoded route.

Note: This basically always happens when using a space character in the destination url but only happens sometimes, when the unencoded character is another one, such as 'ä'. This makes the behavior of the canDeactivate() hook kinda random.

I know that there was already a fix for this in https://github.com/aurelia/router/pull/616 ,but it seems that there are still problems when using unencoded special characters in the destination uri.

Expected/desired behavior:

bigopon commented 5 years ago

This can and should be fixed from history-browser module. The target is here https://github.com/aurelia/history-browser/blob/4cf18cf4bef2461915b94d0b4e9babd975b77cf3/src/browser-history.ts#L274

Basically change from

return '/' + fragment.replace(routeStripper, '');

to

return decodeURIComponent('/' + fragment.replace(routeStripper, ''));
davismj commented 5 years ago

I couldn't reproduce this issue. Is there a repro?