@@ -40,13 +40,14 @@ export function matchContentToUrl (location) {
4040 // This is a bit of a hack to make up for the fact that react-router does
4141 // not always provide the match params as expected.
4242 // https://github.com/ReactTraining/react-router/issues/5870#issuecomment-394194338
43- const root = location . pathname . split ( '/' ) [ 1 ]
43+ let root = location . pathname . split ( '/' ) [ 1 ]
4444 const match = matchPath ( location . pathname , {
4545 path : `/${ root } /:id` ,
4646 exact : true ,
4747 strict : false
4848 } )
4949 const id = match && match . params && match . params . id
50+ console . log ( location , id )
5051 switch ( root ) {
5152 case 'route' :
5253 if ( id ) {
@@ -65,9 +66,16 @@ export function matchContentToUrl (location) {
6566 dispatch ( setMainPanelContent ( MainPanelContent . STOP_VIEWER ) )
6667 }
6768 break
69+ case 'start' :
6870 case '@' :
6971 // Parse comma separated params (ensuring numbers are parsed correctly).
70- const [ lat , lon , zoom , routerId ] = id . split ( ',' ) . map ( s => isNaN ( s ) ? s : + s )
72+ let [ lat , lon , zoom , routerId ] = id ? idToParams ( id ) : [ ]
73+ if ( ! lat || ! lon ) {
74+ // Attempt to parse path. (Legacy UI otp.js used slashes in the
75+ // pathname to specify lat, lon, etc.)
76+ [ , , lat , lon , zoom , routerId ] = idToParams ( location . pathname , '/' )
77+ }
78+ console . log ( 'Setting start position/zoom/router' , lat , lon , zoom , routerId )
7179 // Update map location/zoom and optionally override router ID.
7280 dispatch ( setMapCenter ( { lat, lon } ) )
7381 dispatch ( setMapZoom ( { zoom } ) )
@@ -82,6 +90,10 @@ export function matchContentToUrl (location) {
8290 }
8391}
8492
93+ function idToParams ( id , delimiter = ',' ) {
94+ return id . split ( delimiter ) . map ( s => isNaN ( s ) ? s : + s )
95+ }
96+
8597/**
8698 * Event listener for responsive webapp that handles a back button press and
8799 * sets the active search and itinerary according to the URL query params.
0 commit comments