Skip to content

Instantly share code, notes, and snippets.

@nwebpro
Last active October 15, 2022 08:57
Show Gist options
  • Save nwebpro/5f4741d08b35f7eebc521c7621aec37e to your computer and use it in GitHub Desktop.
Save nwebpro/5f4741d08b35f7eebc521c7621aec37e to your computer and use it in GitHub Desktop.
React Route File Create
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;
import React from 'react';
import { Outlet } from 'react-router-dom';
import Header from './Header';
const Root = () => {
return (
<div>
<Header />
<Outlet />
</div>
);
};
export default Root;
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