No use with react-router v4
See original GitHub issueWhen I click the <Link>
to redirect, the url in browser correctly change but nothing happen in the page.
Here is my code:
// Root.tsx
import * as React from 'react'
import createBrowserHistory from 'history/createBrowserHistory'
import {Link, Route, Switch} from 'react-router-dom'
import {Provider} from 'mobx-react'
import {Router} from 'react-router'
import {syncHistoryWithStore, RouterStore} from 'mobx-react-router'
const routing = new RouterStore()
const browserHistory = createBrowserHistory()
const history = syncHistoryWithStore(browserHistory, routing)
function PageHome () {
return (
<div>
<h1>home</h1>
<Link to='/404'>404</Link>
</div>
)
}
function Page404 () {
return (
<div>
<h1>404</h1>
<Link to='/'>home</Link>
</div>
)
}
export default class Root extends React.Component<void, void> {
render () {
return (
<Provider routing={routing}>
<Router history={history}>
<Switch>
<Route path='/' exact component={PageHome}/>
<Route component={Page404}/>
</Switch>
</Router>
</Provider>
)
}
}
// index.tsx
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import Root from './Root'
import {AppContainer} from 'react-hot-loader'
import './styles/base.styl'
const render = (Root: any) => {
ReactDOM.render(
<AppContainer>
<Root/>
</AppContainer>,
document.getElementById('app')
)
}
render(Root)
if (module.hot) {
module.hot.accept('./Root', () => {
const nextRoot = require('./Root').default
render(nextRoot)
})
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
React router v4 redirect when no match - Stack Overflow
For anybody arriving here looking for how to redirect if none of the routes matches: <Switch> // ... your routes <Route render={() ...
Read more >React Router DOM v4 Tutorial (with Examples) - ITNEXT
In this tutorial we are going to get you started with react-router-dom using an example React application showing you how to use different...
Read more >Handling 404 pages (catch all routes) with React Router v4
In this post you'll learn how to implement catch all routes for handling 404 pages with React Router v4.
Read more >All About React Router 4 - CSS-Tricks
This post is going to dig into to React Router 4, how it's so different from previous React Router versions, and why that...
Read more >A Simple React Router v4 Tutorial - Blog
Build a small single-page application using React Router v4 ... Here it is. No fancy styling, just a simple, functional website.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone having this issue, I ended up using
@withRouter
like so in myApp.jsx
and that seemed to do the trick.Let me know if there’s still issues. New version 4.0.1 is now out.