Route cancellation
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
A method in router API that allows aborting upcoming route change.
Current Behavior
Right now router exposes abortComponentLoad
method but it seems to be designed only for internal use and it doesn’t work if it’s called in routeChangeStart
handler. It works only after this piece of code was executed:
async fetchComponent (route, as) {
let cancelled = false
const cancel = this.componentLoadCancel = function () {
cancelled = true
}
Workaround:
Router.ready(() => {
Router.router.on('routeChangeStart', () => {
setTimeout(() => {
Router.router.abortComponentLoad();
});
});
});
Context
This is useful for example when building complex forms and we want to warn a user before he leaves the page without submitting.
Your Environment
ANY
Issue Analytics
- State:
- Created 6 years ago
- Reactions:105
- Comments:59 (4 by maintainers)
Top Results From Across the Web
Route Terms and Conditions
Cancellation of the Agreement must be in writing and received by Route at least five (5) days before the end of the month....
Read more >Cancel route | Navigation services | Support and legal ...
To simply cancel a route, tap on Cancel (the cross) in the navigation view. You can also delete ongoing directions as follows: Tap...
Read more >bus trips cancellations
BUS TRIPS CANCELLATIONS ... Routes and Schedules · SacRT BusTracker · Google Trip Planner · Accessible Services · Holiday Schedule · Service Alerts ......
Read more >Route cancellation - Sygic GPS Navigation for iOS - 16.4.
To cancel the current route, please open the Quick menu and tap on Cancel Route button.
Read more >Route cancellation · Discussion #32231 · vercel/next.js
_cancel = false let err = new Error('Abort') err.cancelled = true throw err } } // set global._cancel = true whenever you want...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Even with this, I can’t get your code working. But, I found another way to do it that works for me:
The full code in TypeScript (I rewrote @Betree solution with hooks and by removing intl, etc…):
then add:
at the beginning of your page/component.
Please, let me know if there is any issue with my code or if you see how to improve it.
I wonder if we’ll ever have an official API for this, it’s been almost 4 years.