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
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
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
You need to use props inside your onchange function to go to another page.
this.props.history.push('/my-other-components-url');
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>
)
}