Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- componentWillReceiveProps() {
- this.contextTypes = {
- history: React.PropTypes.object
- }
- },
- _handleRoute(e) {
- e.preventDefault()
- this.history.pushState(null, `/somepath`);
- },
- render() {
- return(
- <div onClick={this._handleRoute}>
- Some Content.
- </div>
- );
- }
- render() {
- return(
- <div>
- <Link to={`/somepath`}> link </Link>
- </div>
- );
- }
- //Router Component
- render ()
- return (
- <SomeComponent changeRoute={this.props.history.pushState}
- )
- //SomeComponent
- onClick() {
- this.props.changeRoute(null, 'somepath', {query: "something"});
- }
- import {browserHistory} from 'react-router';
- //SomeComponent
- browserHistory.push('somepath');
- location.hash: '/some-route?sheeps=black';
- "history": "^4.6.3",
- "react": "^15.6.1",
- "react-dom": "^15.6.1",
- "react-router": "^4.1.2",
- "react-router-dom": "^4.1.2",
- "webpack": "^3.3.0",
- "webpack-dev-server": "^2.5.1"
- import {BrowserRouter,Route,Link} from 'react-router-dom'; // for BrowserRouter rout
- <BrowserRouter>
- <div>
- <Route exact path='/' component={Layout}></Route>
- <Route path='/about' name="about" component={about}> </Route>
- <Route path='/protfolio' name="protfolio" component={protfolio}></Route>
- </div>
- </BrowserRouter >
- <Link to="/about">Check rout link protfolio</Link>
- <Link to="/protfolio">Check rout link protfolio</Link>
- <button onClick={this.navigate.bind(this)}>button binf</button>
- navigate(){
- this.props.history.replace('/', null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement