What they did in that page is a bit tricky.
The trick is creating a new history with history.pushState
and then subscribe to the pop event of the location to change the webpage to the home .
I suggest to do something a little different and easier, that code only needs this lines:
let locat = location.href;
if (!!window.location.pathname && window.location.pathname !== '/') {
history.replaceState(null,null,location.origin);
history.pushState(null, null,locat);
}
What we do here it's change the url to the home you want with history.replaceState(null,null,location.origin);
and then make a new entry in the history with history.pushState(null, null,locat);
witht he first url.
Example here:
https://stackblitz.com/edit/angular-stack-home-redirect-history?file=src/app/app.component.ts
Try it out here:
https://angular-stack-home-redirect-history.stackblitz.io/bye