Skip to content

Commit

Permalink
fix: add location observer to fix webcomponent routing (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjakobi authored Jul 4, 2024
1 parent 756ec90 commit 9ab9389
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ function connectMicroFrontendRouter(injector: Injector) {
}

function connectRouter(router: Router): void {
const url = `${location.pathname.substring(getLocation().deploymentPath.length)}${location.search}`
router.navigateByUrl(url)
window.addEventListener('popstate', () => {
router.navigateByUrl(url)
})
const initialUrl = `${location.pathname.substring(getLocation().deploymentPath.length)}${location.search}`
router.navigateByUrl(initialUrl)
let lastUrl = location.href
new MutationObserver(() => {
const url = location.href
if (url !== lastUrl) {
lastUrl = url
const routerUrl = `${location.pathname.substring(getLocation().deploymentPath.length)}${location.search}`
router.navigateByUrl(routerUrl)
}
}).observe(document, { subtree: true, childList: true })
}

0 comments on commit 9ab9389

Please sign in to comment.