routert.js 中:
<Router> <Switch> <Route exact path="/" component={Login}></Route> <Route path="/*" component={Layout}></Route> </Switch> </Router>
在Layout 组件中:
<Router>
<Switch> <Route path={`/car/list`} component={car_list} /> <Route path={`/car/details`} component={car_details} /> <Route path={`/car/create`} component={car_create} /> </Switch>
</Router>
出现了从car/details 跳转到 car/list 时出路径改变但是页面停留在car_details的问题,最终发现Layout组件中不能再出现<Router></Router>,否则就会出现上述问题。
最终将Layout组件改为:
<Switch> <Route path={`/car/list`} component={car_list} /> <Route path={`/car/details`} component={car_details} /> <Route path={`/car/create`} component={car_create} /> </Switch>
每一个坑都是我成长的脚印。