1- import RouterAsync from 'router-async' ;
1+ import { Router as RouterAsync , Context } from 'router-async' ;
22import * as React from 'react' ;
33import { deepMap } from './helpers' ;
44
@@ -43,11 +43,16 @@ export default class Router extends React.Component<Props, State> {
4343 this . router = props . router ;
4444 this . history = props . history ;
4545 }
46- static async init ( { path, routes, hooks, ctx = { } } ) {
46+ static async init ( { path, routes, hooks, ctx = new Context ( ) } ) {
4747 const plainRoutes = Router . buildRoutes ( routes ) ;
4848 const router = new RouterAsync ( { routes : plainRoutes , hooks } ) ;
49- const { result , redirect, status } = await router . resolve ( { path, ctx } ) ;
49+ const { route , status , params , redirect, result } = await router . resolve ( { path, ctx } ) ;
5050 let props = {
51+ path,
52+ route,
53+ status,
54+ params,
55+ redirect,
5156 ctx
5257 } ;
5358 return {
@@ -57,7 +62,7 @@ export default class Router extends React.Component<Props, State> {
5762 status,
5863 router,
5964 props,
60- callback : this . makeCallback ( router )
65+ callback : this . makeCallback ( router , { path , route , status , params , redirect , result , ctx } )
6166 }
6267 }
6368 static buildRoutes ( routes ) {
@@ -103,7 +108,7 @@ export default class Router extends React.Component<Props, State> {
103108 get location ( ) {
104109 return this . state . location ;
105110 }
106- async navigate ( path , ctx = { } ) {
111+ async navigate ( path , ctx = new Context ( ) ) {
107112 try {
108113 const { redirect } = await this . router . match ( { path, ctx } ) ;
109114 if ( redirect ) {
@@ -112,25 +117,29 @@ export default class Router extends React.Component<Props, State> {
112117 this . history . push ( path ) ;
113118 }
114119 } catch ( error ) {
115- if ( this . props . errorHandler ) {
116- this . props . errorHandler ( error , this ) ;
117- } else {
120+ this . history . push ( path ) ;
121+ if ( ! this . props . errorHandler ) {
118122 console . error ( 'Match Error' , path , error ) ;
119123 throw error ;
120124 }
121125 }
122126 }
123127 private _locationChanged = async ( location , action ) => {
124128 try {
125- const { result, ctx } = await this . router . resolve ( { path : location . pathname } ) ;
129+ const { path , route , status , params , redirect , result, ctx } = await this . router . resolve ( { path : location . pathname } ) ;
126130 let props = {
131+ path,
132+ route,
133+ status,
134+ params,
135+ redirect,
127136 ctx
128137 } ;
129138 this . setState ( {
130139 Component : result ,
131140 location,
132141 props
133- } , Router . makeCallback ( this . router ) ) ;
142+ } , Router . makeCallback ( this . router , { path , route , status , params , redirect , result , ctx } ) ) ;
134143 } catch ( error ) {
135144 if ( this . props . errorHandler ) {
136145 this . props . errorHandler ( error , this ) ;
0 commit comments