Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to pass params with history.push?

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;

========================= Get Sent 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

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

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

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

How to pass params with history.push?

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 history push search params

pathname, search
Comment

How to pass params with history.push?

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

PREVIOUS NEXT
Code Example
Javascript :: for loop on a array 
Javascript :: bootstrap 5.1 3 tooltip not working 
Javascript :: golang parse jason 
Javascript :: compare two dates using moment 
Javascript :: using iframe in chrome console 
Javascript :: json.stringify formatting 
Javascript :: how to use async await inside useeffect 
Javascript :: get date js 
Javascript :: reduce parameters 
Javascript :: get the next character javascript 
Javascript :: convert elements to array javascript 
Javascript :: loop through array backwards 
Javascript :: hot reload problem react 17 
Javascript :: javascript format date object to yyyy-mm-dd 
Javascript :: add class jquery 
Javascript :: react native load function each time visit screen 
Javascript :: angular filter ngfor 
Javascript :: show hide more text jquery 
Javascript :: javascript spread and rest operator 
Javascript :: remove duplicate items from array 
Javascript :: predicate function javascript 
Javascript :: loop in object javascript 
Javascript :: javascript to remove duplicates from an array 
Javascript :: React import image with url 
Javascript :: angular cli generate component 
Javascript :: regex for exactly n digits 
Javascript :: sort object dictionary javscript 
Javascript :: debounce react 
Javascript :: convert string in hh:mm am/pm to date js 
Javascript :: `useFindAndModify` is an invalid option. 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =