Skip to content

Instantly share code, notes, and snippets.

@dev-cyprium
Created February 22, 2021 22:17
Show Gist options
  • Select an option

  • Save dev-cyprium/367cd666af0ee35ebb672f46cf48abe2 to your computer and use it in GitHub Desktop.

Select an option

Save dev-cyprium/367cd666af0ee35ebb672f46cf48abe2 to your computer and use it in GitHub Desktop.
// router/index.js
const RouterView = ({ config, notFound }) => {
const router = useRouter();
let Component = config[router.route] || null;
let NotFound = notFound;
return Component ? <Component /> : <NotFound />;
};
// App.js (modify)
// ...
const Page404 = () => (
<div>
<h1>Whops, the page you're looking for is not found</h1>
<Link href="/">
<button className="text-indigo-500">Go Home</button>
</Link>
</div>
);
export default function App() {
/* ... */
return (<AppRouter>
{/* ... */}
<RouterView
notFound={Page404}
config={{ "/": Home, "/page": Page }}
/>
{/* ... */}
</AppRouter>);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment