-
Notifications
You must be signed in to change notification settings - Fork 1
Router Snippets
Nick S. Plekhanov edited this page Sep 8, 2016
·
1 revision
import React from 'react';
import { Route, IndexRoute, Redirect } from 'react-router';
import App from './App';
import MainView from 'components/MainView';
import NotFoundView from 'components/NotFound';
export default (
<Route path="/" component={App}>
<IndexRoute component={MainView} />
<Route path="404" component={NotFoundView} />
<Redirect from="*" to="404" />
</Route>
);
import { render } from 'react-dom';
import { Router } from 'react-router';
import { browserHistory } from 'react-router';
import routes from './routes';
render(
<Router history={browserHistory} routes={routes} />,
document.getElementById('app')
);
<Link to="/${1:route}">${2:Title}</Link>
<Link to="/${1:about}" activeClassName="${2:active}">${3:About}</Link>
<IndexLink to="/" activeClassName="${1:active}">${2:Home}</IndexLink>
<Link to="/" activeClassName="${1:active}" onlyActiveOnIndex={true}>${2:Home}</Link>
static contextTypes = {
router: PropTypes.object.isRequired
};
import React, { Component } from 'react';
import { Link } from 'react-router';
export default class NavLink extends Component {
render() {
return <Link {...this.props} activeClassName="${1:active}" />;
}
}
<NavLink to="/${1:route}">${2:Title}</NavLink>
this.props.params.${1:name}
this.context.router.push('/${1:route}');
<IndexRoute component={${1:Main}} />
<Route path="${1:name}" component={${2:Component}} />
<Redirect from="${1:/route/:id}" to="${2:/another/:id}" />