Answer the question
In order to leave comments, you need to log in
How to programmatically change the path in Reac Router?
There are two components. The first component is shown immediately. How to use React Router to show the second, for example, after 10 seconds? Application without server side.
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
var ComponentOne = React.createClass({
componentDidMount: function () {
setTimeout(function () {
browserHistory.push('/two')
}, 5000);
},
render: function () {
return (
<div className="one">Component One</div>
);
}
});
var ComponentTwo = React.createClass({
render: function () {
return (
<div className="two">Component Two</div>
);
}
});
ReactDOM.render((
<Router history={browserHistory}>
<Route path="/" component={ComponentOne}>
<IndexRoute component={ComponentOne}/>
<Route path="/two" component={ComponentTwo} />
</Route>
</Router>
), document.getElementById('app'));
Answer the question
In order to leave comments, you need to log in
Confusion in the question:
1) how to programmatically change the path?
2) how to use RR to show the second component after 10 seconds?
That is, you need to change the route, for example, after 10 seconds? (so the component belonging to that route will be shown).
You can programmatically change the route using push , replace (ibid.). There are also examples, one of them .
In componentDidMount of the first component, set a timer to redirect to the second component.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question