Nauman Zafar
Nauman Zafar

Reputation: 1103

React nested routes issue

I have a couple of routes setup using Route from react-router-dom.

<Route exact path="/dashboard/search" component={Search} />

<Route exact path="/dashboard/search/:uid/:sid/result" component={Results} />

Problem

The second route mentioned above is something I send to an email as a link. When I click that link. It opens up the link with url as expected but doesn't stay there and takes to the first route. Simply put.

  1. 2nd route url shows up in address bar.
  2. Then switches to first route.

As you can see I do have exact prop setup on this. Shouldn't they be differentiated? What could be the problem?

Upvotes: 0

Views: 60

Answers (2)

Muhammad Ateek
Muhammad Ateek

Reputation: 1057

It will help you, you need to setup node server which will return main page of the application on every request.

React-router urls don't work when refreshing or writing manually

Upvotes: 0

Rana
Rana

Reputation: 126

This code will help you

<Route path="/Product" name="Product" >
    <IndexRoute component={Product} />
    <Route path="add" name="Add product" component={AddProduct} />
    <Route path="edit/:id" name="Edit product" component={AddProduct} />
    <Redirect from="edit" to="/product" />
    <Route path="detail/:id" name="Detail" component={DetailProduct} />
    <Redirect from="edit" to="/product" /></Route>

Upvotes: 2

Related Questions