In React Router 4 I can define
<Route path="/calendar/:view/:year?/:month?/:day?" component={Calendar} />
to pass props from a URL to my Calendar component.
Inside the Calendar component, I want to programmatically set the URL params. The docs show how to do this using history.push()
, but this requires you to format the URL yourself like history.push(``${view}/${year}/${month}/${day}``)
. But I want to update the URL without being coupled to the route structure, ideally something like history.push({ view: 'month', year: '2018' })
.
Is this possible? It seems odd to me that React Router helps split up the URL into params, but doesn't provide a nice mechanism to set those params?