-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Router method to execute custom logic before popstate events #3956
Add Router method to execute custom logic before popstate events #3956
Conversation
@gcpantazis I'm okay to take this feature this in. But not as a solution to #2682 |
lib/router/router.js
Outdated
@@ -51,6 +52,12 @@ export default class Router { | |||
} | |||
|
|||
async onPopState (e) { | |||
// If the downstream application returns falsy, return. | |||
// They will then be responsible for handling the event. | |||
if (!this._beforePopState(e.state)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this after the following if condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks @arunoda + @timneutkens. I did check |
Going to merge this in, can't think of a different way to solve this, maybe we'll change it in the future. |
Fixes #4008,
popstate
allows the Router to client-render pages that should be blocked byuseFileSystemPublicRoutes: false
. See comment here.This commit adds a pre-hook into
Router
's response topopstate
, which allows the downstream user to inject their own functionality / cancel Router's response if they'd like to handle it themselves. See README update for docs.Example usage: https://github.com/gcpantazis/nextjs-playground/tree/uFSPR-solutionA
cc/ @timneutkens