Skip to content

Commit

Permalink
fix: router hash for github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
steveblue committed Oct 12, 2024
1 parent 7af4c98 commit 4ccb39d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ JavaScript microlibrary for developing Web Components with Decorators that uses

Chat with us on [Dischord](https://discord.gg/xzsnBfD3fu).

For more information, read the [Readymade documentation](https://readymade-ui.github.io/readymade).

### Getting Started

Install Readymade:
Expand Down
10 changes: 6 additions & 4 deletions src/modules/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class Router {
} else {
if (this.hashMode && !window.location.hash.length) {
window.location.href =
window.location.origin + window.location.pathname + `/#/`;
window.location.origin +
window.location.pathname.replace(/\/$/, '') +
`/#/`;
} else {
path = window.location.pathname.replace(/\/$/, '');
}
Expand All @@ -94,7 +96,7 @@ class Router {
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}',
'"}'
);
}

Expand All @@ -118,7 +120,7 @@ class Router {
resolve(route: Route) {
const locationParams = this.decodeQuery();
const component: RouteComponent = document.createElement(
route.component as string,
route.component as string
);

if (Object.keys(locationParams).length) {
Expand All @@ -127,7 +129,7 @@ class Router {
window.history.replaceState(
{},
'',
`${location.pathname}?${this.parseQuery(route)}`,
`${location.pathname}?${this.parseQuery(route)}`
);
}

Expand Down

0 comments on commit 4ccb39d

Please sign in to comment.