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

Using stop() still changes the URL to the next path #62

Closed
jasongrishkoff opened this issue Feb 18, 2019 · 11 comments
Closed

Using stop() still changes the URL to the next path #62

jasongrishkoff opened this issue Feb 18, 2019 · 11 comments
Labels

Comments

@jasongrishkoff
Copy link

When firing stop() inside of the global triggers.exit, the expected behavior is that the user is not taken to the next route. From what I can see, FlowRouter still updates all its internals to reflect that we're on the new route, even though the page doesn't actually change.

FlowRouter.triggers.exit([pageChange])
pageChange = function(context,redirect,stop) {                                                                        
   if (context.path.indexOf('step=') > -1                                                                         
        && !confirm('Are you sure you want to leave this page?'                                                       
            + ' You haven\'t finished yet.')                                                          
    ) {
        stop()
    }
}

This guy seems to have had a similar problem and solved it, but the pull request was never merged?
kadirahq#681

@dr-dimitru
Copy link
Member

Hello @jasongrishkoff ,

Very sorry for late reply. Could you describe in more details in more details, is the URL in the browser get changed? Is the new template get rendered?

Note: You can't call stop() from async callback

@jasongrishkoff
Copy link
Author

The URL gets changed, but the template does not get rendered.

@dr-dimitru
Copy link
Member

@jasongrishkoff do you have any errors or exceptions in a browser/server console? Sound's like routing was interrupted by something

@dr-dimitru
Copy link
Member

@jasongrishkoff let me know if you have more details or it's got solved.

@jasongrishkoff
Copy link
Author

There are no errors in the browser/server console.

@dr-dimitru
Copy link
Member

@jasongrishkoff Minimal reproduction would help a lot. Marked [help wanted]

@dr-dimitru
Copy link
Member

Hey @jasongrishkoff,

I believe right after you call .stop() you should redirect to other route or render another template.
Described behavior matching expected as .stop() will interrupt routing chain of actions, in your case interruption happens between changing URI and rendering new template.

Feel free to close it in case if the issue is solved on your end.

@jasongrishkoff
Copy link
Author

To me, "stop" would imply that I want to cancel my routing and stay where I am. The fact that it only fires after the URI has changed seems wrong. I've already used a workaround, so in a sense this is solved.

@dr-dimitru
Copy link
Member

@jasongrishkoff would you share your workaround?

@jasongrishkoff
Copy link
Author

jasongrishkoff commented Apr 27, 2019

I basically just trigger the back button.

FlowRouter.triggers.enter([loaderBar,pageChange])
pageChange = function(context,redirect,stop) {
  if (!confirm('Are you sure you want to leave this page?') {
    stop()
    setTimeout(() => { window.history.back() })
  }
}

@dr-dimitru
Copy link
Member

@jasongrishkoff thank you.

We did additional checking, there is no easy way (or at least we haven't found any) to change this behavior, this part remained unchanged from original flow router.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants