Skip to content

Commit 2a4cfc5

Browse files
authored
move ctx away frome history state
1 parent 61d6376 commit 2a4cfc5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/browser-router.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class BrowserRouter extends Router {
1111
super(props);
1212
this.history = props.history;
1313
this.stateFromServer = null;
14+
this.__CTX__ = null;
1415
if (window && '__REACT_ROUTER_ASYNC__' in window) {
1516
this.stateFromServer = window['__REACT_ROUTER_ASYNC__'].state;
1617
if (this.stateFromServer.error !== null) {
@@ -42,12 +43,17 @@ export default class BrowserRouter extends Router {
4243
const { redirect, error } = await this.router.resolve({ path, ctx });
4344
if (error === null) {
4445
if (redirect) {
45-
this.history.push(redirect, { ctx });
46+
this.__CTX__ = ctx;
47+
this.history.push(redirect);
4648
} else {
47-
this.history.push(path, { ctx });
49+
this.__CTX__ = ctx;
50+
this.history.push(path);
4851
}
4952
} else {
50-
if (error.message !== 'Cancelled') this.history.push(path);
53+
if (error.message !== 'Cancelled') {
54+
this.__CTX__ = ctx;
55+
this.history.push(path);
56+
}
5157
}
5258
}
5359
async push(path, ctx = new Context()) {
@@ -75,7 +81,10 @@ export default class BrowserRouter extends Router {
7581
if (this.router.isRunning) this.router.cancel();
7682
const currentTransition = this.router.currentTransition;
7783
let opts = { path, ctx: new Context() };
78-
if (state && state.ctx) opts.ctx = state.ctx;
84+
if (this.__CTX__) {
85+
opts.ctx = this.__CTX__;
86+
this.__CTX__ = null;
87+
}
7988
let { location, route, status, params, redirect, result, ctx, error } = await this.router.run(opts);
8089
if (error && error.message === 'Cancelled') return;
8190
if (error !== null && error.message !== 'Cancelled') {

0 commit comments

Comments
 (0)