fix(error): fix incorrect 'view on IMDb' link on error page
the error was due to a faulty logic. 'useRouter' was being used to detect pathname, which doesn't keep original url on 404 page. this commit fixes that. this commit also makes it easy to go to IMDb by adding a clear link on error page. closes https://github.com/zyachel/libremdb/issues/50
This commit is contained in:
25
src/pages/[...error]/index.tsx
Normal file
25
src/pages/[...error]/index.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { GetServerSideProps, InferGetServerSidePropsType } from 'next';
|
||||
import ErrorInfo from 'src/components/error/ErrorInfo';
|
||||
|
||||
const error = {
|
||||
statusCode: 404,
|
||||
message: 'Not found, sorry.',
|
||||
} as const;
|
||||
|
||||
type Props = InferGetServerSidePropsType<typeof getServerSideProps>;
|
||||
|
||||
const Error404 = ({ originalPath }: Props) => {
|
||||
return <ErrorInfo {...error} originalPath={originalPath} />;
|
||||
};
|
||||
|
||||
export default Error404;
|
||||
|
||||
type Data = { originalPath: string };
|
||||
type Params = { error: string[] };
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx => {
|
||||
ctx.res.statusCode = error.statusCode;
|
||||
ctx.res.statusMessage = error.message;
|
||||
|
||||
return { props: { originalPath: ctx.resolvedUrl } };
|
||||
};
|
Reference in New Issue
Block a user