74
rated 0 times
[
78]
[
4]
/ answers: 1 / hits: 16198
/ 6 Years ago, thu, january 11, 2018, 12:00:00
I have code
router.js
import React from 'react';
import {render} from react-dom;
import history from './history';
import {Router, Route} from 'react-router'
import Main from ./main/component;
import Profile from ./profile/component;
import TextStatus from ./textstatus/component;
import ContactList from ./contactlist/component;
render((
<Router history={history}>
<Main>
<Route
path=/:user_name
component={Profile}
component_id=Profile
/>
<Route
path=/:user_name/status
component={TextStatus}
component_id=TextStatus
/>
<Route
path=/:user_name/contacts
component={ContactList}
component_id=ContactList
/>
</Main>
</Router>
), document.getElementById(main));
history.js
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory();
export default history;
main/component.js //main layout
import React from 'react';
class Main extends React.Component {
render() {
return (this.props.children)
}
}
How can I get the current route (component_id) in Main component?
In react router 1.0.3 I did this: this.props.children.props.route.component_id
Thank you for attention!
More From » reactjs