Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
- JakubDrozd
- jamesrwilliams
- janpaepke
- jaschaio
- jasikpark
- jasonpaulos
- jdufresne
Expand Down
38 changes: 17 additions & 21 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2394,28 +2394,24 @@ export function createRouter(init: RouterInit): Router {
if (blockerFunctions.size === 0) {
return;
}

// We ony support a single active blocker at the moment since we don't have
// any compelling use cases for multi-blocker yet
if (blockerFunctions.size > 1) {
warning(false, "A router only supports one blocker at a time");
}

let entries = Array.from(blockerFunctions.entries());
let [blockerKey, blockerFunction] = entries[entries.length - 1];
let blocker = state.blockers.get(blockerKey);

if (blocker && blocker.state === "proceeding") {
// If the blocker is currently proceeding, we don't need to re-check
// it and can let this navigation continue
return;
}

// At this point, we know we're unblocked/blocked so we need to check the
// user-provided blocker function
if (blockerFunction({ currentLocation, nextLocation, historyAction })) {
return blockerKey;
}
let blockingKey: string | undefined = undefined;
entries.some(entry=>{
let [blockerKey, blockerFunction] = entry;
let blocker = state.blockers.get(blockerKey);
if (blocker && blocker.state === "proceeding") {
// If the blocker is currently proceeding, we don't need to re-check
// it and can let this navigation continue
return;
}
// At this point, we know we're unblocked/blocked so we need to check the
// user-provided blocker function
if (blockerFunction({ currentLocation, nextLocation, historyAction })) {
blockingKey = blockerKey;
return blockerKey;
}
});
return blockingKey;
}

function cancelActiveDeferreds(
Expand Down