Reactjs,如何将 props.location.pathname 与字符串进行比较?
Reactjs, How to compare props.location.pathname to a string?
在我的路由器中,我需要执行以下操作:
if (props.location.pathname !== '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
if 语句未按预期运行。
如果我输出:
console.log(props.location.pathname)
我进入了控制台。
/confirm
但是,具有“/confirm”值的 props.location.pathname
不被视为与 /confirm
相同
我做错了什么?
两个操作数的类型在使用 == 时应该相同 comparision.Make 确保两者都是字符串类型或更改为
if (props.location.pathname != '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
要比较 React.js 中的两个字符串,您可以简单地使用 三重等于 (或 ===),如下所示:
if (stringTemp === 'desired string'){
console.log('Equal');
}
在我的路由器中,我需要执行以下操作:
if (props.location.pathname !== '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
if 语句未按预期运行。
如果我输出:
console.log(props.location.pathname)
我进入了控制台。
/confirm
但是,具有“/confirm”值的 props.location.pathname
不被视为与 /confirm
我做错了什么?
两个操作数的类型在使用 == 时应该相同 comparision.Make 确保两者都是字符串类型或更改为
if (props.location.pathname != '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
要比较 React.js 中的两个字符串,您可以简单地使用 三重等于 (或 ===),如下所示:
if (stringTemp === 'desired string'){
console.log('Equal');
}