diff --git a/components/nav.js b/components/nav.js index ccc249c..d3e37c0 100644 --- a/components/nav.js +++ b/components/nav.js @@ -3,7 +3,7 @@ import Link from 'next/link' const links = [ { href: 'https://zeit.co/now', label: 'ZEIT' }, - { href: 'https://github.com/zeit/next.js', label: 'GitHub' }, + { href: '/about/', label: 'About' }, ].map(link => { link.key = `nav-link-${link.href}-${link.label}` return link diff --git a/pages/_error.js b/pages/_error.js new file mode 100644 index 0000000..15f44d6 --- /dev/null +++ b/pages/_error.js @@ -0,0 +1,24 @@ +import Error from "next/error"; +import Router from "next/router"; + +export default Error; + +Error.getInitialProps = ({ res, err, asPath }) => { + const statusCode = res ? res.statusCode : err ? err.statusCode : 404; + + if (statusCode && statusCode === 404) { + if (asPath.match(/\/$/)) { + const withoutTrailingSlash = asPath.substr(0, asPath.length - 1); + if (res) { + res.writeHead(302, { + Location: withoutTrailingSlash + }); + res.end(); + } else { + Router.push(withoutTrailingSlash); + } + } + } + + return { statusCode }; +};