1

How to redirect a component based on a selected drop down value and button click in react using react router dom ?

I have tried using Redirect tag but i am unable to redirect to another component

3 Answers3

2

Link component from react-router can be used for this:

<Link to="/other-components-url">
    <button>Click Me!</button>
</Link>

Any UI element can be nested in "Link" component which when clicked will redirect to specified URL/Component.

For more details visit: https://knowbody.github.io/react-router-docs/api/Link.html

0

You need to use props inside your onchange function to go to another page.

this.props.history.push('/my-other-components-url');
Ertan Hasani
  • 1,675
  • 12
  • 27
0
import React from 'react'
import Button from 'react-bootstrap/Button'
import { Link } from "react-router-dom"; 
import { useParams } from "react-router"; 
export const Parent component ()=>{

return(
  <Link to={"/child" + 12 + " "} >
  <Button className="btn btn-icon btn-round  " >  Redirect   </Button>
    </Link>
)
}

 
 
export const Child component ()=>{
 
 let { id} = useParams();
return(
  <div>hello danish your id is : {id}</div>
)
}
Danish
  • 47
  • 3