Last active
October 15, 2022 08:57
-
-
Save nwebpro/5f4741d08b35f7eebc521c7621aec37e to your computer and use it in GitHub Desktop.
React Route File Create
This file contains 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
import React from 'react'; | |
import { RouterProvider } from 'react-router-dom'; | |
import { router } from './Routes'; | |
const App = () => { | |
return ( | |
<div> | |
<RouterProvider router={router} /> | |
</div> | |
); | |
}; | |
export default App; |
This file contains 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
import React from 'react'; | |
import { Outlet } from 'react-router-dom'; | |
import Header from './Header'; | |
const Root = () => { | |
return ( | |
<div> | |
<Header /> | |
<Outlet /> | |
</div> | |
); | |
}; | |
export default Root; |
This file contains 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
import { createBrowserRouter } from "react-router-dom"; | |
import Root from "./components/Root"; | |
import Home from "./Pages/Home"; | |
import ErrorPage from "./Pages/ErrorPage"; | |
export const router = createBrowserRouter([ | |
{ | |
path: '/', | |
element: <Root />, | |
errorElement: <ErrorPage />, | |
children: [ | |
{ | |
path: '/', | |
element: <Home /> | |
}, | |
{ | |
path: '/home', | |
element: <Home /> | |
}, | |
] | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment