在我的路由器中,我需要执行以下操作:
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
不同
我究竟做错了什么?
使用==进行比较时,两个操作数的类型应该相同。确保两者都是字符串类型或更改是否为
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');
}