My routes are defined as follows:
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="experiments">
<IndexRoute component={Experiments} />
</Route>
<Route path="*" component={NoMatch}/>
</Route>
</Router>
When I visit /experiments, things work as expected and the Experiments component is rendered. However, when I manually enter a URL with query parameters, example: /experiments?offset=50, the route doesn't match!
But when I navigate using <Link to={{ pathname='/experiments', query={offset:50} }} />, things work as expected. The Experiments component is rendered and this.props.location.query.offset is set to 50.
How do I get the Route to match when a URL with query string is entered manually (or copy-pasted)?
It seems route should match automatically url-with-query-string-not-matching-react-router-route, but it doesn't seem to be working for me.
Edit:
I narrowed down the problem to the catch-all route path="*". When I remove this route, everything works (e.g. when I visit /experiments?offset=50). But no routes are matched when the catch-all Route is present, even though it is at the bottom of the precedence list.
You need to make use of
historyApiFallbackwithhistory={browserHistory}to load your route when you manually enter it.what
historyApiFallbackdoes, is make it so your server returnsindex.htmlfor whatever URL you try to access and since your routes are then configured with respect toindex.htmlso you can access any of the route url directlyIn you webpack add