导航到另一个子路由而无需编写父路由(ReactRouter)

时间:2021-05-09 15:30:47

标签: reactjs react-router

我目前有这样的路由器设置

const App = () => {
  return (
    <BrowserRouter>
      <Switch>
        <Route exact path="/" component={FutureMeLandingPage} />
        <Route path="/career-me" component={CareerMeRoutes} />
        <Route path="/dashboard" component={StudentDashboard} />
        <Route component={NotFoundPage} />
      </Switch>
    </BrowserRouter>
  );
};

const CareerMeRoutes = ({ match }: RouteComponentProps) => (
  <>
    <Route exact path={match.path} component={CareerMeLandingPage} />
    <Route path={`${match.path}/test`} component={CareerMeTestIntroPage} />
    <Route path={`${match.path}/home`} component={CareerMeHomePage} />
    <Route path={`${match.path}/subjects`} component={SubjectListPage} />
  </>
);

当我在介绍页面 (/career-me/home) 时,是否可以导航到主题页面 (/career-me/subject) 而不必写“/career-me”?我觉得有点多余。

0 个答案:

没有答案