Better route cancellation example, addresses #1856

This commit is contained in:
Barney Carroll 2021-04-15 23:52:14 +01:00 committed by Stephan Hoyer
parent cd087347f7
commit 70aff8cd69

View file

@ -859,15 +859,13 @@ m.route(document.body, "/", {
### Route cancellation / blocking
RouteResolver `onmatch` can prevent navigation away from the current route by returning a promise that never resolves:
RouteResolver `onmatch` can prevent route resolution by returning a promise that never resolves. This can be used to detect attempted redundant route resolutions and cancel them:
```javascript
var blocked = true
m.route(document.body, "/", {
"/": {
onmatch: function(args) {
if (blocked)
onmatch: function(args, requestedPath) {
if (m.route.get() === requestedPath)
return new Promise(function() {})
},
},