Ako získať trasy z iných lokalít/funkcia v reagovať-router-dom v6?

0

Otázka

Snažím Reagovať Router V06, ale čelí problému, kde som sa snažil to pod túto cestu, ale každý trasy a stránky sú prázdne.

Kód:

// Main App Function
    const App = () => {
      return (
        <Router>
          <Fragment>
            <Navbar />
            <Routes>
              <Route index strict path="/" element={<Landing />} />
      **{/* Here I want to render paths from other function*/}**
              <Route element={<AppRoutes />} />
            </Routes>
          </Fragment>
        </Router>
      );
    };
    
    export default App;
    
    // In AppRoutes Function
    const AppRoutes = () => (
      <section className="container">
        <Routes>
          <Route strict path="login" element={<Login />} />
          <Route strict path="register" element={<Register />} />
          <Route path="*" element={<NotFound />} />
        </Routes>
      </section>
    );
    
    export default AppRoutes;
1

Najlepšiu odpoveď

1

V app, vyhlásiť Landing komponent byť index stránky, a zobrazovať AppRoutes na "/*" cesta umožniť zodpovedajúce sub-trasy.

Aplikácia

<Router>
  <Navbar />
  <Routes>
    <Route index element={<Landing />} />
    <Route path="/*" element={<AppRoutes />} />
  </Routes>
</Router>

AppRoutes

const AppRoutes = () => (
  <section className="container">
    <Routes>
      <Route path="login" element={<Login />} />
      <Route path="register" element={<Register />} />
      <Route path="*" element={<NotFound />} />
    </Routes>
  </section>
);

Edit how-to-get-routes-from-other-location-function-in-react-router-dom-v6

2021-11-24 00:18:18

Vďaka, hlúposť ma, nevedel som prísť na to malý problém. Je to funguje skvele!
Gazi

@Gazi Žiadne starosti, sa stane pre nás všetkých niekedy. Nechcem zabudnúť na to, čo robiť, keď niekto odpovie. Na zdravie!
Drew Reese

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................