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

View File

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

View File

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