【发布时间】:2020-02-02 18:25:57
【问题描述】:
我已经在 App.js 中设置了我的 React 路由器。页面组件会渲染。当我点击一个链接时,页面组件将不会呈现,但浏览器中的 URL 会更改为“page/{id}”。为什么是这样?
页面组件:
function Pages(props) { const managedPages = JSON.parse(localStorage.getItem("managedPages")); console.log(managedPages);
return (
<div>
<List>
{managedPages.map(page => (
<ListItem key={page.id}>
<Link
to={`/page/${page.id}`}
style={{ textDecoration: "none", color: "black" }}
>
<ListItemText primary="Teszt Színház" />
</Link>
</ListItem>
))}
</List>
<Route path="/page" component={Page} />
</div> ); }
App.js jsx:
return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<BrowserRouter>
<div className="App">
<BarAndMenu
userLoginAndDataDownloadCompletedOut={
this.userLoginAndDataDownloadCompletedOut
}
/>
</div>
<Switch>
<Route path="/" exact component={OngoingEventList} />
<Route path="/selectSeat" component={SelectSeat} />
<Route path="/releasePurpose/:id" component={ReleasePurpose} />
<Route
path="/marketingResourceConfigurationAndResult/:id"
component={MarketingResourceConfigurationAndResult}
/>
<Route path="/myTickets" exact component={MyTicketList} />
<Route path="/myTickets/:id" component={MyTicket} />
<Route path="/auditoriumList/:id" component={AuditoriumSelector} />
<Route path="/pages" component={Pages} />
</Switch>
</BrowserRouter>
</MuiPickersUtilsProvider utils={MomentUtils}>
);
【问题讨论】:
标签: reactjs react-router