Created
February 22, 2021 22:17
-
-
Save dev-cyprium/367cd666af0ee35ebb672f46cf48abe2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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