【发布时间】:2020-04-18 17:24:02
【问题描述】:
我有以下路由模式:
<Router history={history}>
<Route path="/" exact render={DashboardPage}/>
<Route path="/accounts/:id" exact render={AccountPage} />
</Router>
const AccountPage = (props) => {
const {match: {params}} = props;
const id = _.toInteger(params.id);
return (
<Layout>
<AccountComponent id={id}/>
</Layout>
)
};
我已经在商店中拥有所有现有帐户,因此无需进行 Ajax 调用来确认存在。 我的问题是:如何处理 id 与任何现有资源不匹配的情况?
【问题讨论】:
-
我认为您需要在
AccountPage组件中处理此问题,如果id不存在,请重定向到未找到的 URL。
标签: reactjs react-redux react-router react-router-dom react-router-redux