I need a View component and an Edit component. Depends on conditions, a button needs to go View page or Edit page.
I set a Route like below. The problem is the paths are the same.
<Route exact path='/users/:user_id' component={Users.Edit} />
<Route exact path='/users/:user_id' component={Users.View} />
In page, I have links like below
(type = "A") ? <Link to="users/1">view</Link> : <Link to="users/1">edit</Link>
For now, the router has same path so the button goes to the Edit component.
Is there any good react way I can call Edit component or View component? or Do I need to just like below?
<Route exact path='/users/:user_id' component={Users.Edit} />
<Route exact path='/users/:user_id/view' component={Users.View} />
Routes if you don't actually need routes? URL doesn't change, so why use routes? You can just have a state variable that points to eitherVieworEdit, and render your component based on that.