1

我对 React Router Dom 有一个奇怪的问题。在我的代码中,我有:

if (this.state.area) {
return (<Redirect push to = {'/ service_list'} />)
}

在 url 中它正确写入“localhost:3000 / list_services,但它似乎没有加载页面。如果我按回车键或重新加载页面,它会正确显示。有人可以帮助我吗?在我的路由文件中我有:

<Route exact path="/emilia_romagna">
  <Home/>
</Route>
<Route exact path="/lista_servizi">
  <ListaServizi/>
</Route>
4

1 回答 1

0

重写此模型:

import { BrowserRouter, Route } from "react-router-dom";

<BrowserRouter>
    <Route exact path="/emilia_romagna" component={Home} />
    <Route exact path="/lista_servizi" component={ListaServizi} />
    <Router component={NotFound} /> // Add this line and write the Not Found component to ensure that other paths mapped correctly.
</BrowserRouter>
于 2021-03-13T11:44:08.867 回答