Answers for "send data with history.push react"

5

passing data in react router history,push

this.props.history.push({
  pathname: '/template',
  search: '?query=abc',
  state: { detail: response.data }
})
Posted by: Guest on February-05-2021
4

history.push with params

import { useHistory } from "react-router-dom";

const FirstPage = props => {
    let history = useHistory();

    const someEventHandler = event => {
       history.push({
           pathname: '/secondpage',
           search: '?query=abc',
           state: { detail: 'some_value' }
       });
    };

};

export default FirstPage;
Posted by: Guest on August-26-2020
2

history.push with params

import { useEffect } from "react";
import { useLocation } from "react-router-dom";

const SecondPage = props => {
    const location = useLocation();

    useEffect(() => {
       console.log(location.pathname); // result: '/secondpage'
       console.log(location.search); // result: '?query=abc'
       console.log(location.state.detail); // result: 'some_value'
    }, [location]);

};
Posted by: Guest on August-26-2020
3

passing data in react router history,push

<Link to={{
      pathname: '/template',
      search: '?query=abc',
      state: { detail: response.data }
    }}> My Link </Link>
Posted by: Guest on February-05-2021
2

passing data in react router history,push

this.props.location.state.detail
Posted by: Guest on February-05-2021

Code answers related to "send data with history.push react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language