Skip to content

Commit a6db427

Browse files
committed
Fixing trailing slash issue on page reload
Fixing trailing slash issue - when navigating from home to any city (ex: boston) and reload the page, somehow '\' is added to the end of location.href, which breaks the routing. This code will remove the trailing slash Taken from angular-ui/ui-router#50 (comment)
1 parent b926dbf commit a6db427

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: lib/main.js

+9
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ function makeHtmlGenerator(serverScripts, prepContext, clientScripts, template,
140140
var path = reqContext.location.path();
141141
var search = reqContext.location.search();
142142

143+
//Fixing trailing slash issue - when navigating from home to any city (ex: boston) and reload the page, somehow '\' is added to the end of location.href, which breaks the routing.
144+
//This code will remove the trailing slash
145+
//Taken from https://github.com/angular-ui/ui-router/issues/50#issuecomment-64895625
146+
var re = /(.+)(\/+)(\?.*)?$/
147+
if(re.test(path)) {
148+
path = path.replace(re, '$1$3')
149+
}
150+
//End of fix
151+
143152
var matchedRoute = $route.getByPath(path, search);
144153

145154
if (matchedRoute) {

0 commit comments

Comments
 (0)