“React History Push Search Params” Kode Jawaban

Sejarah. Pusat dengan 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;

Precious Panda

Sejarah. Pusat dengan 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]);

};
Precious Panda

Param Pencarian Dorong Sejarah

this.props.history.push({
    pathname: '/client',
    search: "?" + new URLSearchParams({clientId: clientId}).toString()
})
Alive Antelope

React History Push Search Params

pathname, search
Agreeable Addax

Jawaban yang mirip dengan “React History Push Search Params”

Pertanyaan yang mirip dengan “React History Push Search Params”

Lebih banyak jawaban terkait untuk “React History Push Search Params” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya