하는 방법에서 경로를 다른 위치/함수에 반응하-라우터 dom v6?

0

질문

내가 노력하고 반응 라우터 V06 지만,문제에 직면한 어 려고 노력했습니다 이 아래 방법이지만 모든 경로 및 페이 비어 있습니다.

코드:

// 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

최고의 응답

1

응용 프로그램에서 선언 Landing 구성 요소 인덱스 페이지로 렌더링 AppRoutes 에"/*"경로에 일치할 수 있도록 하위 노선이 있습니다.

<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

감사,바,나이 없는 이 작은 문제입니다. 그것은 작동이 위대하다!
Gazi

@Gazi 걱정 없이,우리 모두 때로는. 것을 잊지 마세 무엇을 할 때 누군가가 답. Cheers!
Drew Reese

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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