How to achieve similar behaviour as beforePopState of NextJSrouter #8078
Unanswered
SergioArrighi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I have been looking into this matter for a couple of days without any success.
In NextJS there is a router with the following capability
`
useEffect(() => {
router.beforePopState(({ as }) => {
if (as !== router.asPath) {
// Will run when leaving the current page; on back/forward actions
// Add your logic here, like toggling the modal state
}
return true;
});
`
Basically it can fire an event before a POP event.
I didn't find a way to do this in React Router V6.
I tried also to use this package https://www.npmjs.com/package/history and the createBrowserHistory hook, but I only can intercept events on the destination page and not in the source component.
Thanks in advance in regards
Beta Was this translation helpful? Give feedback.
All reactions