Skip to content

Commit 21552cc

Browse files
committed
cancellation of current transition
1 parent c4eafee commit 21552cc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/browser-router.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ export default class BrowserRouter extends Router {
3737
};
3838
}
3939
async navigate(path, ctx = new Context()) {
40+
// TODO: better cancellation
41+
if (this.router.isRunning) this.router.cancel();
4042
const { redirect, error } = await this.router.resolve({ path, ctx });
4143
if (error === null) {
4244
if (redirect) {
4345
this.history.push(redirect);
4446
} else {
4547
this.history.push(path);
4648
}
47-
} else if (error && error.message === 'Already running') {
48-
console.warn('Router already running');
4949
} else {
5050
this.history.push(path);
5151
}
@@ -72,8 +72,11 @@ export default class BrowserRouter extends Router {
7272
}
7373
private _locationChanged = async ({ pathname, hash, search }, historyAction) => {
7474
const path = pathname + search + hash;
75+
// TODO: better cancellation
76+
if (this.router.isRunning) this.router.cancel();
7577
let { location, route, status, params, redirect, result, ctx, error } = await this.router.run({ path });
76-
if (error !== null) {
78+
if (error && error.message === 'Cancelled') return;
79+
if (error !== null && error.message !== 'Cancelled') {
7780
result = Router.getErrorComponent(error, this.errors);
7881
}
7982
const props = {

0 commit comments

Comments
 (0)