1
1
import * as React from 'react' ;
2
2
import Router , { initParams , initResult } from './router' ;
3
- import { Context } from 'router-async' ;
3
+ import { Context , stringifyQuery } from 'router-async' ;
4
4
5
5
export default class BrowserRouter extends Router {
6
6
private history : any ;
@@ -40,6 +40,16 @@ export default class BrowserRouter extends Router {
40
40
}
41
41
}
42
42
}
43
+ async push ( path ) {
44
+ // console.warn('Please use navigate method instead of push, it will be deprecated in future');
45
+ if ( typeof path === 'string' ) {
46
+ await this . navigate ( path ) ;
47
+ } else {
48
+ let fullPath = path . pathname ;
49
+ if ( path . query ) fullPath += `?${ stringifyQuery ( path . query ) } ` ;
50
+ await this . navigate ( fullPath ) ;
51
+ }
52
+ }
43
53
// TODO: maybe we need to make this history methods works through navigate?
44
54
goBack ( ) {
45
55
this . history . goBack ( ) ;
@@ -50,9 +60,10 @@ export default class BrowserRouter extends Router {
50
60
go ( n ) {
51
61
this . history . go ( n ) ;
52
62
}
53
- private _locationChanged = async ( { pathname } ) => {
63
+ private _locationChanged = async ( { pathname, hash, search } ) => {
64
+ const path = pathname + search + hash ;
54
65
try {
55
- const { path , location, route, status, params, redirect, result, ctx } = await this . router . run ( { path : pathname } ) ;
66
+ const { location, route, status, params, redirect, result, ctx } = await this . router . run ( { path } ) ;
56
67
const props = {
57
68
router : {
58
69
path,
0 commit comments