我有我的react路由器代码,如下所示。。。
<Router>
<Switch>
<Route path='/login' exact component={Login} />
<Route path='/clients/:slug' exact>
{props.isAuthenticated ? (
<ClientLayout>
<Switch>
<Route exact path="/clients/:slug/planning/:planning_id/short-term-plans/:id" component={ShortTermPlan} />
<Route exact path="/clients/:slug/planning/:id" component={Planning} />
<Route exact path="/clients/:slug" component={Client} />
</Switch>
</ClientLayout>
) : <Redirect to="/login" />}
</Route>
<Route>
{props.isAuthenticated ? (
<ApplicationLayout>
<Switch>
<Route exact path="/" component={Clients} />
<Route exact path="/programs" component={Programs} />
<Route exact path="/programs/new" component={NewProgram} />
<Route exact path="/programs/:id/workouts" component={EditProgram} />
<Route exact path="/library/exercises" component={Exercises} />
<Route exact path="/library/exercises/new" component={NewExercise} />
<Route exact path="/library/exercises/:id/edit" component={EditExercise} />
<Route component={NotFound} />
</Switch>
</ApplicationLayout>
) : <Redirect to="/login" />}
</Route>
</Switch>
</Router>
当我转到以下URL时,我会发现"未找到"。
http://localhost:3000/clients/john-doe/planning/1
任何帮助都将不胜感激:(
更新
我已经删除了?并重新排序第二路由中的路由,但仍然没有改变。
如前所述,在第二个<Route>
元素中,有一个?在路径道具中。此外,重要的建议是,对于大多数路线,尽量在较短路线之前列出较长路线。请参阅我以前的回答之一:原因在这里。