Update 404 page

This commit is contained in:
LordMathis 2018-06-15 17:30:20 +02:00
parent 80760d895f
commit 960c12fe9d
5 changed files with 46 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Route, Switch } from 'react-router-dom'; import { Route, Switch } from 'react-router-dom';
import { Home, NotFoundPage } from '.'; import { Home, NotFoundWrapper } from '.';
import { MainContainer, PostContainer } from '../containers'; import { MainContainer, PostContainer } from '../containers';
export const App = () => ( export const App = () => (
@ -8,7 +8,7 @@ export const App = () => (
<Switch> <Switch>
<Route exact path="/" component={MainContainer} /> <Route exact path="/" component={MainContainer} />
<Route path="/post/:postname" component={PostContainer} /> <Route path="/post/:postname" component={PostContainer} />
<Route component={NotFoundPage} /> <Route component={NotFoundWrapper} />
</Switch> </Switch>
</div> </div>
); );

View File

@ -1,17 +1,18 @@
import React from 'react'; import React from 'react';
import {Navbar, Header} from '.';
import '../static/stylesheets/globals.scss'; import '../static/stylesheets/globals.scss';
import contentStyle from '../static/stylesheets/content.scss'; import contentStyle from '../static/stylesheets/content.scss';
export const NotFoundPage = (props) => { export const NotFoundPage = (props) => {
if (props.location.pathname === '/') {
return null;
}
return ( return (
<div> <div>
<Navbar />
<div className={contentStyle.contentWrapper}> <div className={contentStyle.contentWrapper}>
<h1>Uhm... WHAT?</h1> <Header header={"Uhm... WHAT?"} />
<h2>Looks like you&apos;re lost</h2> <div className={contentStyle.content}>
<p>404 Page not found</p> <p>Looks like you&apos;re lost</p>
<p>404 Page not found</p>
</div>
</div> </div>
</div> </div>
); );

View File

@ -0,0 +1,15 @@
import React, {Component} from 'react';
import {Wrapper, NotFoundPage} from '.';
import '../static/stylesheets/globals.scss';
import styles from './Wrapper.scss';
export default class NotFoundWrapper extends Component {
render () {
return (
<Wrapper>
<NotFoundPage />
</Wrapper>
)
}
}

View File

@ -3,6 +3,7 @@ export { default as Blog } from './Blog';
export { default as About } from './About'; export { default as About } from './About';
export { default as Post } from './Post'; export { default as Post } from './Post';
export { default as NotFoundPage } from './NotFoundPage'; export { default as NotFoundPage } from './NotFoundPage';
export { default as NotFoundWrapper } from './NotFoundWrapper';
export { default as Spinner } from './Spinner'; export { default as Spinner } from './Spinner';
export { default as Header } from './Header'; export { default as Header } from './Header';
export { default as Wrapper } from './Wrapper'; export { default as Wrapper } from './Wrapper';

View File

@ -1,6 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import axios from 'axios'; import axios from 'axios';
import {Post, Wrapper} from '../components'; import {Post, Wrapper, NotFoundPage} from '../components';
export default class PostContainer extends Component { export default class PostContainer extends Component {
constructor() { constructor() {
@ -8,6 +8,7 @@ export default class PostContainer extends Component {
this.state = { this.state = {
isLoading: true, isLoading: true,
error: false,
}; };
} }
@ -15,14 +16,29 @@ export default class PostContainer extends Component {
const url = '/api/post/' + this.props.match.params.postname; const url = '/api/post/' + this.props.match.params.postname;
axios.get(url).then((res) => { axios.get(url).then((res) => {
this.setState({ if (res.data.error) {
isLoading: false, this.setState({
post: res.data, error: true,
}); });
}
else {
this.setState({
error: false,
isLoading: false,
post: res.data,
});
}
}) })
} }
render() { render() {
if (this.state.error) {
return (
<NotFoundPage />
)
}
return ( return (
<Wrapper> <Wrapper>
<Post isLoading={this.state.isLoading} <Post isLoading={this.state.isLoading}