From 0aea2f47dad6eb78e319ea1abd8c444f2cba4424 Mon Sep 17 00:00:00 2001
From: zyachel
Date: Sat, 3 Jun 2023 22:12:54 +0530
Subject: [PATCH] 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
---
next.config.mjs | 23 +++++++------------
src/components/error/ErrorInfo.tsx | 16 +++++++++++---
src/interfaces/shared/error.ts | 8 +++----
src/layouts/Header.tsx | 34 ++++++++---------------------
src/layouts/Layout.tsx | 5 +++--
src/pages/[...error]/index.tsx | 25 +++++++++++++++++++++
src/pages/find/index.tsx | 22 +++++++++++++------
src/pages/name/[nameId]/index.tsx | 15 ++++++++-----
src/pages/title/[titleId]/index.tsx | 15 ++++++++-----
9 files changed, 94 insertions(+), 69 deletions(-)
create mode 100644 src/pages/[...error]/index.tsx
diff --git a/next.config.mjs b/next.config.mjs
index ff6f94a..adbc227 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -2,21 +2,14 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
- async rewrites() {
- return {
- afterFiles: [
- {
- source: '/',
- destination: '/find',
- },
- ],
- fallback: [
- {
- source: '/:path*',
- destination: '/404',
- },
- ],
- };
+ async redirects() {
+ return [
+ {
+ source: '/',
+ destination: '/find',
+ permanent: true,
+ },
+ ];
},
images: {
domains: ['m.media-amazon.com'],
diff --git a/src/components/error/ErrorInfo.tsx b/src/components/error/ErrorInfo.tsx
index e42b55e..07cca5f 100644
--- a/src/components/error/ErrorInfo.tsx
+++ b/src/components/error/ErrorInfo.tsx
@@ -11,7 +11,8 @@ import styles from 'src/styles/modules/components/error/error-info.module.scss';
type Props = {
message: string;
statusCode?: number;
- // props specific to error boundary.
+ originalPath?: string;
+ /** props specific to error boundary. */
misc?: {
subtext: string;
buttonText: string;
@@ -19,12 +20,12 @@ type Props = {
};
};
-const ErrorInfo = ({ message, statusCode, misc }: Props) => {
+const ErrorInfo = ({ message, statusCode, misc, originalPath }: Props) => {
const title = statusCode ? `${message} (${statusCode})` : message;
return (
<>
-
+
)}
diff --git a/src/interfaces/shared/error.ts b/src/interfaces/shared/error.ts
index 477d852..9beabf8 100644
--- a/src/interfaces/shared/error.ts
+++ b/src/interfaces/shared/error.ts
@@ -1,5 +1,3 @@
-export type AppError = {
- message: string;
- statusCode: number;
- stack?: any;
-};
+import { AppError as AppErrorClass } from 'src/utils/helpers';
+
+export type AppError = Omit, 'name'>;
diff --git a/src/layouts/Header.tsx b/src/layouts/Header.tsx
index b95c9e5..5154742 100644
--- a/src/layouts/Header.tsx
+++ b/src/layouts/Header.tsx
@@ -1,21 +1,14 @@
-import { ReactNode } from 'react';
-import { useRouter } from 'next/router';
import Link from 'next/link';
import ThemeToggler from 'src/components/buttons/ThemeToggler';
import styles from 'src/styles/modules/layout/header.module.scss';
-type Props = { full?: boolean; children?: ReactNode };
-
-const Header = (props: Props) => {
- const { asPath: path } = useRouter();
+type Props = { full?: boolean; originalPath?: string };
+const Header = ({ full, originalPath }: Props) => {
return (
-