React Router How to have parent routes and sub routes with paramters
up vote
0
down vote
favorite
I have 2 routes:
<Route path="/hello/:name" component={A}>
<Route path="/hello/custom/:name" component={B}>
Now when I navigate to /hello/custom/aPerson. Component A and B are called. How can I avoid that? Currently I have to add logic to component A to check its param :name to see if any "/" is used. If so, I disable component A.
react-router
add a comment |
up vote
0
down vote
favorite
I have 2 routes:
<Route path="/hello/:name" component={A}>
<Route path="/hello/custom/:name" component={B}>
Now when I navigate to /hello/custom/aPerson. Component A and B are called. How can I avoid that? Currently I have to add logic to component A to check its param :name to see if any "/" is used. If so, I disable component A.
react-router
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have 2 routes:
<Route path="/hello/:name" component={A}>
<Route path="/hello/custom/:name" component={B}>
Now when I navigate to /hello/custom/aPerson. Component A and B are called. How can I avoid that? Currently I have to add logic to component A to check its param :name to see if any "/" is used. If so, I disable component A.
react-router
I have 2 routes:
<Route path="/hello/:name" component={A}>
<Route path="/hello/custom/:name" component={B}>
Now when I navigate to /hello/custom/aPerson. Component A and B are called. How can I avoid that? Currently I have to add logic to component A to check its param :name to see if any "/" is used. If so, I disable component A.
react-router
react-router
asked Nov 8 at 23:32
TrongBang
196211
196211
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The fix is to add exact
to the routes.
<Route exact path="/hello/:name" component={A}>
<Route exact path="/hello/custom/:name" component={B}>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The fix is to add exact
to the routes.
<Route exact path="/hello/:name" component={A}>
<Route exact path="/hello/custom/:name" component={B}>
add a comment |
up vote
0
down vote
The fix is to add exact
to the routes.
<Route exact path="/hello/:name" component={A}>
<Route exact path="/hello/custom/:name" component={B}>
add a comment |
up vote
0
down vote
up vote
0
down vote
The fix is to add exact
to the routes.
<Route exact path="/hello/:name" component={A}>
<Route exact path="/hello/custom/:name" component={B}>
The fix is to add exact
to the routes.
<Route exact path="/hello/:name" component={A}>
<Route exact path="/hello/custom/:name" component={B}>
answered Nov 9 at 7:45
TrongBang
196211
196211
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217721%2freact-router-how-to-have-parent-routes-and-sub-routes-with-paramters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown