I'm currently trying to migrate react-router from v3 to v4, but I can't quite grasp the new concepts, my old react-router v3 code looks like this, can someone please take a look and give me some hints?
Thanks!
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute name="index" component={ Index } />
<Route name="documents" path="/documents" component={ Documents } onEnter={ authenticate } />
<Route name="newDocument" path="/documents/new" component={ NewDocument } onEnter={ authenticate } />
<Route name="editDocument" path="/documents/:_id/edit" component={ EditDocument } onEnter={ authenticate } />
<Route name="viewDocument" path="/documents/:_id" component={ ViewDocument } onEnter={ authenticate } />
<Route name="login" path="/login" component={ Login } />
<Route name="recover-password" path="/recover-password" component={ RecoverPassword } />
<Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } />
<Route name="signup" path="/signup" component={ Signup } />
<Route path="*" component={ NotFound } />
</Route>
</Router>
Don't nest routes.
Keep this part
<Router history={ browserHistory }>
<Route path="/" component={ App } />
</Router>
and move all the nesting into <App />
(see here). Also react-router-v4 doesn't have the concept of <IndexRoute />
(see here).
Check out the documentation, it is incredible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With