Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

passing data in react router history,push

this.props.history.push({
  pathname: '/template',
  search: '?query=abc',
  state: { detail: response.data }
})
Comment

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;

Comment

react router history push parameter

this.props.history.push({
  pathname: '/template',
  search: '?query=abc',
  state: { detail: response.data }
})
Comment

How to use history push within function component with parameters?

function Button({ path, text }) {
  const history = useHistory();
  function handle(){
    history.push(path); // This should work now
  }
  return(
    <button onClick={handle}>
      {text} // This should render now
    </button>
  );
}
Comment

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]);

};
Comment

passing data in react router history,push

<Link to={{
      pathname: '/template',
      search: '?query=abc',
      state: { detail: response.data }
    }}> My Link </Link>
Comment

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;
Comment

passing data in react router history,push

this.props.location.state.detail
Comment

How to use history push within function component with parameters?

function Button({ path, text }) {
  const history = useHistory();
  function handle(){
    history.push(path); // This should work now
  }
  return(
    <button onClick={handle}>
      {text} // This should render now
    </button>
  );
}
Comment

react history push search params

pathname, search
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery unbind event 
Javascript :: click outside box jquery 
Javascript :: json get key 
Javascript :: Javscript Add days on Date 
Javascript :: create infinite loop using for loop in javascript 
Javascript :: react native callback function uses default state value 
Javascript :: async storage has been extracted from react-native core 
Javascript :: can we find lenght of an object 
Javascript :: mongoose generate objectid 
Javascript :: xml http request 
Javascript :: random image and link js 
Javascript :: javascript range 
Javascript :: makes number negative javascript 
Javascript :: patch swagger 
Javascript :: axios withcredentials 
Javascript :: material ui textfield error 
Javascript :: react bootstrap card 
Javascript :: react deep copy 
Javascript :: check if string is datestring javascript 
Javascript :: Add event listener for loop 
Javascript :: electron no menu bar 
Javascript :: pushing to an array 
Javascript :: javascript recursive sum function 
Javascript :: console.time in javascript 
Javascript :: async storage get item 
Javascript :: string repeat codewars javascript 
Javascript :: javascript url decode online 
Javascript :: js focus textarea 
Javascript :: javascript ES6 destructure dynamic property name 
Javascript :: safeareaview react native 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =