Skip to content

Commit

Permalink
fix: detect and clean routes without hash (#3757)
Browse files Browse the repository at this point in the history
* fix: detect and clean routes without hash

* fix: add vercel rewrites

* Improve comments
  • Loading branch information
agualis authored Jul 20, 2023
1 parent 22b9460 commit 00080fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/plugins/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ const routes: RouteRecordRaw[] = [
path: '/:networkSlug?',
name: 'home',
component: HomePage,
beforeEnter: (to, from, next) => {
/*
- Correct urls:
These urls will contain a hash (like app.balancer.fi/# or app.balancer.fi/#/polygon).
The hash fragments are not included in window.location.pathname but in window.location.hash
so for those cases window.location.pathname === '/'
- Incorrect urls
These urls will not contain the hash (like app.balancer.fi/polygon/).
Received when the user does not add the hash symbol when manually typing the url in the browser
or when Vercel building a bad redirect without hash after a deployment).
In these cases, the window.location.pathname will contain the wrong fragment/s that we won't to discard.
Example: app.balancer.fi/polygon/ will have window.location.pathname === '/polygon'
*/
if (window.location.pathname !== '/') {
// Remove wrong fragments without hash from pathname
window.location.pathname = '';
}
return next();
},
},
{
path: '/:pathMatch(.*)*',
Expand Down
3 changes: 3 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rewrites": [{ "source": "/:path*", "destination": "/index.html" }]
}

0 comments on commit 00080fb

Please sign in to comment.