Skip to content

Commit 0d20fcc

Browse files
maxwellgordonansonws
authored andcommitted
Catch All Route
1 parent 585863b commit 0d20fcc

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/components/App.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import React, {Component} from 'react';
1+
import React, { Component } from 'react';
22
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
33
import ProductShowPage from './ProductShowPage';
44
import ProductIndexPage from './ProductIndexPage';
55
import NewProductPage from './NewProductPage';
66
import SignInPage from './SignInPage';
77
import HomePage from './HomePage';
88
import NavBar from './NavBar';
9-
import { User, Session } from '../requests'
9+
import { User, Session } from '../requests';
1010
import AuthRoute from './AuthRoute';
11+
import NotFoundPage from './NotFoundPage';
1112

1213
class App extends Component {
1314
constructor(props) {
1415
super(props);
1516
this.state = {
16-
currentUser: null
17-
}
17+
currentUser: null,
18+
};
1819
this.getUser = this.getUser.bind(this);
1920
this.destroySession = this.destroySession.bind(this);
2021
}
@@ -28,7 +29,7 @@ class App extends Component {
2829
if (currentUser.id) {
2930
this.setState({ currentUser });
3031
}
31-
})
32+
});
3233
}
3334

3435
componentDidMount() {
@@ -42,8 +43,12 @@ class App extends Component {
4243
<div className="App">
4344
<NavBar currentUser={currentUser} onSignOut={this.destroySession} />
4445
<Switch>
45-
<Route path="/session/new" exact render={
46-
(routeProps) => <SignInPage {...routeProps} onSignIn={this.getUser} />}
46+
<Route
47+
path="/session/new"
48+
exact
49+
render={routeProps => (
50+
<SignInPage {...routeProps} onSignIn={this.getUser} />
51+
)}
4752
/>
4853
<AuthRoute
4954
isAuth={currentUser}
@@ -64,11 +69,12 @@ class App extends Component {
6469
component={ProductIndexPage}
6570
/>
6671
<Route path="/" exact component={HomePage} />
72+
<Route component={NotFoundPage} />
6773
</Switch>
6874
</div>
6975
</Router>
7076
);
7177
}
72-
};
78+
}
7379

7480
export default App;

src/components/NotFoundPage.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
function NotFoundPage(props) {
4+
return (
5+
<main className="NotFoundPage">
6+
<h1>404 Not Found</h1>
7+
</main>
8+
);
9+
}
10+
11+
export default NotFoundPage;

0 commit comments

Comments
 (0)