admin管理员组文章数量:1397158
I'm using React Router v4 and my client wants a particular feature where adding '/signup' to the end of an existing page's url would cause a signup overlay to appear that asks for a visitor's contact information. After filling out the form in the overlay, the visitor gets redirected to the contents of the original url. It is okay if a savvy visitor works around this by just removing the '/signup' URL.
My question is: how do I acplish that? Should I even be using the path props to check the url?
One problem I foresee is that I cannot anticipate all the potential URLs and structures. I need to be able to take any arbitrary URL that could be nested to the Nth degree. Below are a cases where an overlay would appear:
<Route path="/home/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/home/xx/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/home/xx/yy/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/other/signup" render={({match}) => (
<SomeOverlayForm />
)}>
I tried to look up to see if using regexp in the params is the solution to my problem, but I think it's not, since the regex seems to only check a specific param in question, and does not solve the initially discussed problem of an arbitrary number of forward slashes in the URL (i.e. paths nested by varying degree). See below:
<Route path="home/:someParam(/\/signup$/"} ponent={UserProfilePage} />
I'm pretty confused. So would appreciate guidance not only on a technical solution but how to think about problem/requirement. I am also open to modifying the implementation somewhat. For example, I'd be amenable to maybe using '?signup=true' instead of '/signup'. But the requirement that the thing should be placed at the end of the URL remains the same.
I'm using React Router v4 and my client wants a particular feature where adding '/signup' to the end of an existing page's url would cause a signup overlay to appear that asks for a visitor's contact information. After filling out the form in the overlay, the visitor gets redirected to the contents of the original url. It is okay if a savvy visitor works around this by just removing the '/signup' URL.
My question is: how do I acplish that? Should I even be using the path props to check the url?
One problem I foresee is that I cannot anticipate all the potential URLs and structures. I need to be able to take any arbitrary URL that could be nested to the Nth degree. Below are a cases where an overlay would appear:
<Route path="/home/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/home/xx/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/home/xx/yy/signup" render={({match}) => (
<SomeOverlayForm />
)}>
<Route path="/other/signup" render={({match}) => (
<SomeOverlayForm />
)}>
I tried to look up to see if using regexp in the params is the solution to my problem, but I think it's not, since the regex seems to only check a specific param in question, and does not solve the initially discussed problem of an arbitrary number of forward slashes in the URL (i.e. paths nested by varying degree). See below:
<Route path="home/:someParam(/\/signup$/"} ponent={UserProfilePage} />
I'm pretty confused. So would appreciate guidance not only on a technical solution but how to think about problem/requirement. I am also open to modifying the implementation somewhat. For example, I'd be amenable to maybe using '?signup=true' instead of '/signup'. But the requirement that the thing should be placed at the end of the URL remains the same.
Share Improve this question asked Aug 25, 2017 at 6:15 lukkyjoelukkyjoe 3144 silver badges13 bronze badges 1- Can't you reason your way out of this? I mean, you can put tons of overlay forms on any pages using javascript without the need to dish out a new URL section. I could be wrong but I have never seen any overlay that works like this, like I said, I could be wrong. – Potato Salad Commented Aug 25, 2017 at 6:24
1 Answer
Reset to default 9You can use :params*
. It means zero or more
.
For example:
<Route path="/home/:pageNo*/signup" ponent={Overlay} />
It will match these paths:
// match.params.pageNo contains ""
/home/signup
// match.params.pageNo contains "1"
/home/1/signup
// match.params.pageNo contains "1/2"
/home/1/2/signup
// match.params.pageNo contains "1/2/3"
/home/1/2/3/signup
本文标签: javascriptChecking for a specific url ending using React Router v4Stack Overflow
版权声明:本文标题:javascript - Checking for a specific url ending using React Router v4 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744125582a2591938.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论