# import {createBrowserRouter, Navigate} from "react-router-dom";

<span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">This JavaScript line imports </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for setting up application-wide routing and </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Navigate</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> for programmatic redirection within React Router (v6+), allowing you to define routes and easily redirect users based on conditions or actions in your web application. It's used to configure your app's navigation structure and conditionally send users to different pages or paths.   
  
  
</span>

<span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">createBrowserRouter</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">: Setting Up Routes</span>

- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Purpose:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> Creates a history object for typical browser navigation (using the History API) and enables powerful data APIs (loaders, actions).</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Usage:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> You pass an array of route objects (defining paths and elements to render) to it, then wrap your app with </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">&lt;RouterProvider router={router}&gt;</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. <span class="T286Pc" data-sfc-cp="">.</span><span class="uJ19be notranslate" data-wiz-uids="KaPIT_w,KaPIT_x,KaPIT_y"><span class="vKEkVd" data-animation-atomic=""> </span></span></span>
    
    <div class="Fsg96" data-processed="true" data-sfc-cp="" jsaction="rcuQ6b:&KaPIT_15|npT2md" jscontroller="KHhJQ" jsuid="KaPIT_15">  
    </div>javascript
    
    ```
    import { createBrowserRouter, RouterProvider } from 'react-router-dom';
    import { HomePage } from './pages/HomePage';
    import { AboutPage } from './pages/AboutPage';
    
    const router = createBrowserRouter([
      { path: '/', element: <HomePage /> },
      { path: '/about', element: <AboutPage /> },
    ]);
    
    function App() {
      return <RouterProvider router={router} />;
    }
    
    ```

<span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Navigate</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;">: Programmatic Redirection</span>

- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Purpose:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> A component that renders a &lt;100ms 301 redirect when mounted, useful for authenticated routes or after form submissions.</span>
- <span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Usage:</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;"> Place it inside a component to redirect to a specific </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">to</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> path; use </span><span style="font-size: 13pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">replace</span><span style="font-size: 13pt; font-family: Arial,sans-serif; color: #000000; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> to avoid adding to history (e.g., for auth). </span>

<div class="Fsg96" data-processed="true" data-sfc-cp="" id="bkmrk-" jsaction="rcuQ6b:&KaPIT_1w|npT2md" jscontroller="KHhJQ" jsuid="KaPIT_1w">  
</div><div class="r1PmQe" data-hveid="CAkQAA" data-processed="true" data-wiz-uids="KaPIT_4t,KaPIT_4u,KaPIT_4v" id="bkmrk-javascript" jscontroller="HP6Sjf" jsuid="KaPIT_4s"><div data-processed="true"><div class="pHpOfb" data-animation-atomic="" data-processed="true"><div class="vVRw1d" data-processed="true">javascript</div></div></div></div>```
import { Navigate } from 'react-router-dom';

function ProtectedRoute({ children }) {
  const isAuthenticated = checkAuthStatus(); // Your auth logic
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />; // Redirect if not logged in
  }
  return children;
}

// In your router:
{ path: '/dashboard', element: <ProtectedRoute><Dashboard /></ProtectedRoute> }

```