From 70aff8cd6903c59519e15a5137e958ace0b7beb7 Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Thu, 15 Apr 2021 23:52:14 +0100 Subject: [PATCH] Better route cancellation example, addresses #1856 --- docs/route.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/route.md b/docs/route.md index aa835fc2..a1cae9df 100644 --- a/docs/route.md +++ b/docs/route.md @@ -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() {}) }, },