- 
                Notifications
    
You must be signed in to change notification settings  - Fork 31
 
Fix - Router navigation cancel on error or rejected "before" hook #505
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
base: dev
Are you sure you want to change the base?
Fix - Router navigation cancel on error or rejected "before" hook #505
Conversation
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.
thanks for this contribution @ruggero-nardi !
I've left a few inline comments, could you look at those? Also, this has been added for the route before hook, but not for the beforeEach hook. I guess the same behaviour when rejecting a promise would be expected there?
Other than that, great addition of functionality to the router. Thx!
        
          
                src/components/RouterView.js
              
                Outdated
          
        
      | if (this[symbols.state].preventHashChangeNavigation) { | ||
| this[symbols.state].preventHashChangeNavigation = false | ||
| return | ||
| } | ||
| Router.navigate.apply(this) | 
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.
instead of adding an extra state variable (preventHashChangeNavigation) to the router view, wouldn't it be more clean to keep this contained in the router logic itself?
in that case we would just always call Router.navigate.apply(this) and check a prevent has change variable in the router in the navigate method
| if (isString(beforeHookOutput)) { | ||
| currentRoute = previousRoute | ||
| to(beforeHookOutput) | ||
| return | ||
| } | 
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.
Some changes to this portion have been made by me around the same time as your PR (see: https://github.com/lightning-js/blits/pull/502/files). We should make sure that we keep that functionality in tact
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.
Checked this, updated my dev branch with upstream dev branch and now it has all your changes plus the the additions to the router hooks
          Test Results: ✅ PASSEDRun at: 2025-10-21T08:03:31.469Z Summary:  | 
    
Preventing incorrect navigation on failed or rejected hook
Preventing incorrect navigation on failed or rejected hook
…gero-nardi/blits into fix/router-cancel-navigation
Code change description:
Bug description:
When a route is set to do checks before navigating, the "before" hook works incorrectly when trying to prevent navigation.