我试图将BrowserRouter移出我的组件。我的应用看起来像这样:react-router-dom的BrowserRouter不会渲染组件
class App extends Component {
constructor(props) {
super(props);
this.state = {
}
}
render() {
return (
<BrowserRouter>
<main>
<Menu />
<Switch>
<Route exact path="/about" component = {About} />
<Route exact path="/admin" component = {BooksForm} />
<Route exact path="/cart" component = {Cart} />
<Route exact path="/" component = {BookList} />
</Switch>
<Footer />
</main>
</BrowserRouter>
);
}
}
而且一切工作正常。但是,当我把BrowserRouter了,所以我的index.js看起来像这样:
const renderApp =() => (
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
<App/>
</BrowserRouter>
</Provider>
)
const root = document.getElementById('app')
render(renderApp(), root)
它停止工作。当我点击其中一个链接时,网址会发生变化,但是我的应用没有任何变化。它仅在我重新加载页面时呈现新的元件。如何在不将路由器组件放置在与Switch相同的组件中的情况下使其工作?