React create Router component react-router-dom

    0

    2

    Jose Romero

    reactroutercomponentβ€’β€’β€’
    React TypeScript Recipes

    The above code creates a class that is a router. Inside the class, we have a single route, which is the path "/". This route has a route component that is a <App/> element. The index route is also created, and this route has a <Navigate to="home" /> component.

    Library: react

    Shortcut: react.router.create

    import React from 'react';
    import { Routes, Route, Navigate } from 'react-router-dom';
    import App from 'pages/App';
    
    const Router = () => {
      return (
        <Routes>
          <Route path="/" element={<App />}>
            <Route index element={<Navigate to="home" />} />
          </Route>
        </Routes>
      );
    };
    export default Router;
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.