admin 管理员组文章数量: 1086019
In my router, I need to do the following:
if (props.location.pathname !== '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
The if statement is not acting as expected.
If I output:
console.log(props.location.pathname)
I get in the console.
/confirm
However, props.location.pathname
with the value of '/confirm' is not being seen as the same as /confirm
What am I doing wrong?
In my router, I need to do the following:
if (props.location.pathname !== '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
The if statement is not acting as expected.
If I output:
console.log(props.location.pathname)
I get in the console.
/confirm
However, props.location.pathname
with the value of '/confirm' is not being seen as the same as /confirm
What am I doing wrong?
Share Improve this question asked Jul 4, 2017 at 17:11 AnnaSmAnnaSm 2,3006 gold badges24 silver badges35 bronze badges 3-
2
What is
typeof props.location.pathname
? Strict parisona !== b
is true if types are different. – Yury Tarabanko Commented Jul 4, 2017 at 17:13 -
typeof props.location.pathname
returns string – AnnaSm Commented Jul 4, 2017 at 17:32 -
1
Then it should be ok to use
props.location.pathname !== '/confirm'
. Make sure you don't have some space or special character in "/confirm". – Yury Tarabanko Commented Jul 4, 2017 at 17:35
2 Answers
Reset to default 4To pare two strings in React.js, you can simply use triple-equals (or ===) as below:
if (stringTemp === 'desired string'){
console.log('Equal');
}
type of both the operands should be same while using == for parision.Make sure both are of string type or change if to
if (props.location.pathname != '/confirm') {
// redirect to /confirm to force the user to confirm their email
}
本文标签: javascriptReactJS How to compare propslocationpathname to a stringStack Overflow
版权声明:本文标题:javascript - Reactjs, How to compare props.location.pathname to a string? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1741656668a2308093.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论