@@ -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}
4142export 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