Skip to content

Commit

Permalink
feat: payload adaption of the navigated event to enable navigation in…
Browse files Browse the repository at this point in the history
…formation (#340)

* feat: push latest url to history array

* feat: further changes to correct initialPageLoad
  • Loading branch information
anninowak authored Oct 9, 2024
1 parent 3491e99 commit 917c4d9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,25 @@ export function permissionProxyInitializer(permissionProxyService: PermissionPro
export function configurationServiceInitializer(configurationService: ConfigurationService) {
return () => configurationService.init()
}

let history: string[] = []
let isInitialPageLoad = true
const pushState = window.history.pushState
window.history.pushState = (data: any, unused: string, url?: string) => {
pushState.bind(window.history)(data, unused, url)
new EventsPublisher().publish({
type: 'navigated',
payload: {
url
url,
isFirst: history.length === 0,
history
}
})
if (!isInitialPageLoad) {
history.push(url ?? '')
history = history.slice(-100)
}
isInitialPageLoad = false
}

const replaceState = window.history.replaceState
Expand All @@ -168,9 +178,16 @@ window.history.replaceState = (data: any, unused: string, url?: string) => {
new EventsPublisher().publish({
type: 'navigated',
payload: {
url
url,
isFirst: history.length === 0,
history
}
})
if (!isInitialPageLoad) {
history.push(url ?? '')
history = history.slice(-100)
}
isInitialPageLoad = false
}

export function urlChangeListenerInitializer(router: Router, appStateService: AppStateService) {
Expand Down

0 comments on commit 917c4d9

Please sign in to comment.