File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
src/controllers/memory-router Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { useRef } from 'react' ;
22
33import { createMemoryHistory , MemoryHistoryBuildOptions } from 'history' ;
44
@@ -40,18 +40,29 @@ const getRouterProps = (memoryRouterProps: MemoryRouterProps) => {
4040 */
4141export const MemoryRouter = ( props : MemoryRouterProps ) => {
4242 const { location, children } = props ;
43- const config : MemoryHistoryBuildOptions = { } ;
4443
45- if ( location ) {
46- config . initialEntries = [ location ] ;
44+ const newGetHistory = ( ) =>
45+ createMemoryHistory ( {
46+ initialEntries : location !== undefined ? [ location ] : undefined ,
47+ } ) ;
48+
49+ const historyState = useRef ( {
50+ getHistory : newGetHistory ,
51+ location,
52+ } ) ;
53+
54+ if ( historyState . current . location !== location ) {
55+ historyState . current . getHistory = newGetHistory ;
4756 }
4857
49- const history = createMemoryHistory ( config ) ;
5058 const routerProps = getRouterProps ( props ) ;
5159
5260 return (
5361 // @ts -ignore suppress history will be overwritten warning
54- < Router history = { history } { ...( routerProps as RouterProps ) } >
62+ < Router
63+ history = { historyState . current . getHistory ( ) }
64+ { ...( routerProps as RouterProps ) }
65+ >
5566 { children }
5667 </ Router >
5768 ) ;
You can’t perform that action at this time.
0 commit comments