Skip to content

Commit a12000f

Browse files
authored
Merge pull request #2 from kritua/patch-1
pass through ctx
2 parents c74ecad + 09d2496 commit a12000f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/browser-router.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export default class BrowserRouter extends Router {
4242
const { redirect, error } = await this.router.resolve({ path, ctx });
4343
if (error === null) {
4444
if (redirect) {
45-
this.history.push(redirect);
45+
this.history.push(redirect, { ctx });
4646
} else {
47-
this.history.push(path);
47+
this.history.push(path, { ctx });
4848
}
4949
} else {
5050
if (error.message !== 'Cancelled') this.history.push(path);
@@ -70,11 +70,13 @@ export default class BrowserRouter extends Router {
7070
go(n) {
7171
this.history.go(n);
7272
}
73-
private _locationChanged = async ({ pathname, hash, search }, historyAction) => {
73+
private _locationChanged = async ({ pathname, hash, search, state }, historyAction) => {
7474
const path = pathname + search + hash;
7575
if (this.router.isRunning) this.router.cancel();
7676
const currentTransition = this.router.currentTransition;
77-
let { location, route, status, params, redirect, result, ctx, error } = await this.router.run({ path });
77+
let opts = { path, ctx: new Context() };
78+
if (state.ctx) opts.ctx = state.ctx;
79+
let { location, route, status, params, redirect, result, ctx, error } = await this.router.run(opts);
7880
if (error && error.message === 'Cancelled') return;
7981
if (error !== null && error.message !== 'Cancelled') {
8082
result = Router.getErrorComponent(error, this.errors);

0 commit comments

Comments
 (0)