Skip to content
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

Merged
merged 7 commits into from
Mar 31, 2018

Conversation

gcpantazis
Copy link
Contributor

@gcpantazis gcpantazis commented Mar 6, 2018

Fixes #4008,
popstate allows the Router to client-render pages that should be blocked by useFileSystemPublicRoutes: false. See comment here.

This commit adds a pre-hook into Router's response to popstate, 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

@arunoda
Copy link
Contributor

arunoda commented Mar 14, 2018

@gcpantazis I'm okay to take this feature this in. But not as a solution to #2682
@timneutkens mentioned that, we fixed ^^ issue. Did you check the canary.
He's testing on this at the moment.

@@ -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)) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@gcpantazis
Copy link
Contributor Author

Thanks @arunoda + @timneutkens.

I did check canary this morning, it still breaks for the case in #4008 (but as @timneutkens noted the rest of #2682 is fixed).

@timneutkens
Copy link
Member

Going to merge this in, can't think of a different way to solve this, maybe we'll change it in the future.

@timneutkens timneutkens merged commit 085b2f8 into vercel:canary Mar 31, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants