Skip to content

Commit 65f3fe5

Browse files
authored
Merge pull request #81 from opentripplanner/fix-url-routing
Handle any route w webapp + support otp.js legacy start route
2 parents d215a75 + fe13bce commit 65f3fe5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/actions/ui.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ export function matchContentToUrl (location) {
6565
dispatch(setMainPanelContent(MainPanelContent.STOP_VIEWER))
6666
}
6767
break
68+
case 'start':
6869
case '@':
6970
// Parse comma separated params (ensuring numbers are parsed correctly).
70-
const [lat, lon, zoom, routerId] = id.split(',').map(s => isNaN(s) ? s : +s)
71+
let [lat, lon, zoom, routerId] = id ? idToParams(id) : []
72+
if (!lat || !lon) {
73+
// Attempt to parse path. (Legacy UI otp.js used slashes in the
74+
// pathname to specify lat, lon, etc.)
75+
[,, lat, lon, zoom, routerId] = idToParams(location.pathname, '/')
76+
}
7177
// Update map location/zoom and optionally override router ID.
7278
dispatch(setMapCenter({ lat, lon }))
7379
dispatch(setMapZoom({ zoom }))
@@ -82,6 +88,10 @@ export function matchContentToUrl (location) {
8288
}
8389
}
8490

91+
function idToParams (id, delimiter = ',') {
92+
return id.split(delimiter).map(s => isNaN(s) ? s : +s)
93+
}
94+
8595
/**
8696
* Event listener for responsive webapp that handles a back button press and
8797
* sets the active search and itinerary according to the URL query params.

lib/components/app/responsive-webapp.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class RouterWrapper extends Component {
181181
// to a quirk with react-router.
182182
// https://github.com/ReactTraining/react-router/issues/5870#issuecomment-394194338
183183
'/@/:latLonZoomRouter',
184+
'/start/:latLonZoomRouter',
184185
// Route viewer (and route ID).
185186
'/route',
186187
'/route/:id',
@@ -194,6 +195,10 @@ class RouterWrapper extends Component {
194195
path='/print'
195196
component={PrintLayout}
196197
/>
198+
{/* For any other route, simply return the web app. */}
199+
<Route
200+
render={() => <WebappWithRouter {...this.props} />}
201+
/>
197202
</Switch>
198203
</div>
199204
</ConnectedRouter>

0 commit comments

Comments
 (0)