Skip to content

Commit e17d3b9

Browse files
committed
don't call hooks first time on client in universal apps
1 parent 39b8172 commit e17d3b9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/router.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export interface initParams {
3636
hooks: any,
3737
history?: any,
3838
ctx: any,
39-
errors: any
39+
errors: any,
40+
isUniversal: boolean
4041
}
4142
export interface initResult {
4243
Router?: any,
@@ -69,15 +70,23 @@ export default class Router extends React.Component<Props, State> {
6970
this.subscriber = null;
7071
}
7172
static async init(opts: initParams): Promise<initResult> {
72-
const { path, routes, hooks, history = null, ctx = new Context(), errors } = opts;
73+
const { path, routes, hooks, history = null, ctx = new Context(), errors, isUniversal } = opts;
7374
let plainRoutes;
7475
if ((Array.isArray(routes) && React.isValidElement(routes[0])) || React.isValidElement(routes)) {
7576
plainRoutes = Router.buildRoutes(routes);
7677
} else {
7778
plainRoutes = routes;
7879
}
7980
const router = new RouterAsync({ routes: plainRoutes, hooks });
80-
let { location, route, status, params, redirect, result, error } = await router.run({ path, ctx });
81+
82+
let routerResult: any = {};
83+
if (isUniversal) {
84+
routerResult = await router.resolve({ path, ctx });
85+
} else {
86+
routerResult = await router.run({ path, ctx });
87+
}
88+
let { location, route, status, params, redirect, result, error } = routerResult;
89+
8190
if (error !== null) {
8291
result = Router.getErrorComponent(error, errors);
8392
}

0 commit comments

Comments
 (0)