Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a47b47d

Browse files
committed
Optimze Route
1 parent 37e3295 commit a47b47d

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/routes/PageNotFound/components/PageNotFound.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { Component } from 'react'
22
import NotFoundImage from '../assets/404.jpg'
33
import classes from './PageNotFound.scss'
4+
import { withRouter } from 'react-router';
45

5-
export default class PageNotFound extends Component{
6+
class PageNotFound extends Component{
67

78
back(){
8-
console.log(this.props.router);
9+
this.props.router.goBack()
910
}
1011

1112
render(){
@@ -21,3 +22,4 @@ export default class PageNotFound extends Component{
2122
)
2223
}
2324
}
25+
export default withRouter(PageNotFound)

src/routes/Route/components/Route.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import React, {Component} from 'react'
2-
import { Link } from 'react-router';
2+
import { Link, withRouter } from 'react-router';
33

44
class Route extends Component {
55

6-
/*componentDidMount() {
7-
this.props.router.setRouteLeaveHook(this.props.route, this.routerWillLeave)
8-
}
9-
10-
routerWillLeave(nextLocation) {
11-
return 'Your work is not saved! Are you sure you want to leave?'
12-
}*/
13-
146
redirect () {
15-
console.log(this.props);
16-
}
17-
18-
componentWillReceiveProps (nextProps) {
19-
console.log(nextProps.params.id)
7+
this.props.router.push('/form')
208
}
219

2210
render () {
@@ -25,7 +13,7 @@ class Route extends Component {
2513
return (
2614
<div>
2715
<h1>
28-
Path: <Link to="/route/99">{location.pathname}</Link>
16+
Path: <Link to="/form">{location.pathname}</Link>
2917
</h1>
3018
<div>
3119
<button onClick={this.redirect.bind(this)}>Go</button>
@@ -34,4 +22,4 @@ class Route extends Component {
3422
)
3523
}
3624
}
37-
export default Route
25+
export default withRouter(Route)

0 commit comments

Comments
 (0)