【发布时间】:2018-11-29 20:07:00
【问题描述】:
我有一个/cart 路由,它接受两个名为validate 和email 的查询参数。它们仅在用户未登录时使用,并且在用户登录时是不必要的。在后一种情况下,我想将它们从 URL 中删除。
这是我当前用于/cart 路由的onEnter 函数:
const requireCartLogin = (props, replace) => {
const { email, validate } = props.location.query;
// Exit process if the 'validate' query isn’t present.
if (typeof validate === 'undefined') { return; }
if (!isAuthenticated() || requiresReauthentication()) {
replace({
pathname: '/account/signin',
query: { step: 'signin' },
state: {
email: typeof email !== 'undefined' ? email : null,
auth: true,
next: '/cart'
}
});
} else if (isAuthenticated()) {
replace({
pathname: '/cart',
query: null
});
}
};
条件的第二部分应该删除查询参数,但它目前不起作用。我在这里错过了什么?
【问题讨论】:
-
你有
replace函数的代码吗?可以贴在这里吗? -
@ChetanJadhavCD — 这只是 react-router 历史 API 的一部分:github.com/ReactTraining/react-router/blob/…
-
您使用的是哪个版本的
react-router? -
我正在使用
3.0.4。
标签: reactjs react-router history.js