Snippets / reactjs
Switch Pages Without Refreshing The Page
reactjsReact Router DOM-based solution for seamless page navigation without page refresh.
import React from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import Layout from './Layout.jsx'
import Home from './pages/Home.jsx'
import { createBrowserRouter, createRoutesFromElements, Route, RouterProvider } from 'react-router-dom'
import { AuthProvider } from './store/authenticate.jsx'
const router = createBrowserRouter(
createRoutesFromElements(
<Route path='/' element={<Layout />} >
<Route path='' element={<Home />} />
<Route path='dashboard' element={<Dashboard />} />
<Route path='myblog' element={<MyBlog />} />
<Route path='about' element={<About />} />
<Route path='contact' element={<Contact />} />
<Route path='registration' element={<Registration />} />
<Route path='login' element={<Login />} />
<Route path='logout' element={<Logout />} />
</Route>
)
)
ReactDOM.createRoot(document.getElementById('root')).render(
<>
<AuthProvider>
<RouterProvider router={router} />
</AuthProvider>
</>
)
Sep 17, 2024
Show code