Better route cancellation example, addresses #1856
This commit is contained in:
parent
cd087347f7
commit
70aff8cd69
1 changed files with 3 additions and 5 deletions
|
|
@ -859,15 +859,13 @@ m.route(document.body, "/", {
|
||||||
|
|
||||||
### Route cancellation / blocking
|
### 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
|
```javascript
|
||||||
var blocked = true
|
|
||||||
|
|
||||||
m.route(document.body, "/", {
|
m.route(document.body, "/", {
|
||||||
"/": {
|
"/": {
|
||||||
onmatch: function(args) {
|
onmatch: function(args, requestedPath) {
|
||||||
if (blocked)
|
if (m.route.get() === requestedPath)
|
||||||
return new Promise(function() {})
|
return new Promise(function() {})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue