“React Router DOM V6” Código de respuesta

React Router DOM V6

import {BrowserRouter,Routes,Route,Navigate,Outlet} from "react-router-dom";
<BrowserRouter>
    <Routes>
        <Route path="/" element={<Navigate to="/main" />} />
        <Route path="/home/*" element={<div><Outlet/></div>}>
            <Route path="page1" element={<h1>home page 1</h1>} />
            <Route path="page2" element={<h1>home page 2</h1>} />
        </Route>
        <Route path="/notification" element={<h1>notification page</h1>} />
        <Route path="/notification/:id" element={<h1>notification details pages</h1>} />
        <Route path="/login" element={<h1> login page </h1>} />
    </Routes>
</BrowserRouter>
CodePadding

React Router V6

import React from 'react';
import { BrowserRouter as Router , Route , Routes } from "react-router-dom";
import Landing from "./experimentalComponents/Landing"
import First from "./experimentalComponents/First"
import Second from "./experimentalComponents/First"
import AuthContext from "./contexts/authContext";


const Experiment = () => {
    return (
        <AuthContext> 
            
            <Router> 
                <Routes> 
                    <Route path="/" exact element={<Landing/>}/> 
                    <Route path="/first" exact element={<First/>}/> 
                    <Route path="/second" exact element={<Second/>}/> 
                </Routes>
            </Router>

        </AuthContext>
    )
}

export default Experiment;
Confused Crossbill

React Router DOM V6

//active route --> react router dom@v6
import * as React from "react";
import {
  Routes,
  Route,
  Outlet,
  Link,
  useMatch,
  useResolvedPath,
} from "react-router-dom";
import type { LinkProps } from "react-router-dom";

export default function App() {
  return (
    <div>
      <h1>Custom Link Example</h1>

      <p>
        This example demonstrates how to create a custom{" "}
        <code>&lt;Link&gt;</code> component that knows whether or not it is
        "active" using the low-level <code>useResolvedPath()</code> and
        <code>useMatch()</code> hooks.
      </p>

      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="about" element={<About />} />
          <Route path="*" element={<NoMatch />} />
        </Route>
      </Routes>
    </div>
  );
}

function CustomLink({ children, to, ...props }: LinkProps) {
  let resolved = useResolvedPath(to);
  let match = useMatch({ path: resolved.pathname, end: true });

  return (
    <div>
      <Link
        style={{ textDecoration: match ? "underline" : "none" }}
        to={to}
        {...props}
      >
        {children}
      </Link>
      {match && " (active)"}
    </div>
  );
}

function Layout() {
  return (
    <div>
      <nav>
        <ul>
          <li>
            <CustomLink to="/">Home</CustomLink>
          </li>
          <li>
            <CustomLink to="/about">About</CustomLink>
          </li>
        </ul>
      </nav>

      <hr />

      <Outlet />
    </div>
  );
}

function Home() {
  return (
    <div>
      <h1>Home</h1>
    </div>
  );
}

function About() {
  return (
    <div>
      <h1>About</h1>
    </div>
  );
}

function NoMatch() {
  return (
    <div>
      <h1>Nothing to see here!</h1>
      <p>
        <Link to="/">Go to the home page</Link>
      </p>
    </div>
  );
}
@iinaamasum

React Router V6

import React from 'react';
import ReactDOM from "react-dom";
import {
  BrowserRouter,
  Routes,
  Route,
} from "react-router-dom";
import App from "./App";

ReactDOM.render(
  <BrowserRouter>
    <Routes>
      <Route path="/" element={<App />} />
    </Routes>
  </BrowserRouter>,
  document.getElementById("root");
);
Red Team

React Router V6

function App() {
  return (
    <div>
      <Sidebar>
        <Routes>
          <Route path="/" element={<MainNav />} />
          <Route
            path="dashboard"
            element={<DashboardNav />}
          />
        </Routes>
      </Sidebar>

      <MainContent>
        <Routes>
          <Route path="/" element={<Home />}>
            <Route path="about" element={<About />} />
            <Route path="support" element={<Support />} />
          </Route>
          <Route path="dashboard" element={<Dashboard />}>
            <Route path="invoices" element={<Invoices />} />
            <Route path="team" element={<Team />} />
          </Route>
          <Route path="*" element={<NotFound />} />
        </Routes>
      </MainContent>
    </div>
  );
}
Beautiful Boar

Respuestas similares a “React Router DOM V6”

Preguntas similares a “React Router DOM V6”

Más respuestas relacionadas con “React Router DOM V6” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código