11import * as React from 'react' ;
22import Router , { initParams , initResult } from './router' ;
3- import { Context } from 'router-async' ;
3+ import { Context , stringifyQuery } from 'router-async' ;
44
55export default class BrowserRouter extends Router {
66 private history : any ;
@@ -40,6 +40,16 @@ export default class BrowserRouter extends Router {
4040 }
4141 }
4242 }
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+ }
4353 // TODO: maybe we need to make this history methods works through navigate?
4454 goBack ( ) {
4555 this . history . goBack ( ) ;
@@ -50,9 +60,10 @@ export default class BrowserRouter extends Router {
5060 go ( n ) {
5161 this . history . go ( n ) ;
5262 }
53- private _locationChanged = async ( { pathname } ) => {
63+ private _locationChanged = async ( { pathname, hash, search } ) => {
64+ const path = pathname + search + hash ;
5465 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 } ) ;
5667 const props = {
5768 router : {
5869 path,
0 commit comments