1import { useHistory } from "react-router-dom";
2
3const FirstPage = props => {
4 let history = useHistory();
5
6 const someEventHandler = event => {
7 history.push({
8 pathname: '/secondpage',
9 search: '?query=abc',
10 state: { detail: 'some_value' }
11 });
12 };
13
14};
15
16export default FirstPage;
17
18
1this.props.history.push({
2 pathname: '/template',
3 search: '?query=abc',
4 state: { detail: response.data }
5})
1import { useEffect } from "react";
2import { useLocation } from "react-router-dom";
3
4const SecondPage = props => {
5 const location = useLocation();
6
7 useEffect(() => {
8 console.log(location.pathname); // result: '/secondpage'
9 console.log(location.search); // result: '?query=abc'
10 console.log(location.state.detail); // result: 'some_value'
11 }, [location]);
12
13};
14
1import { useHistory } from "react-router-dom";
2
3const FirstPage = props => {
4 let history = useHistory();
5
6 const someEventHandler = event => {
7 history.push({
8 pathname: '/secondpage',
9 search: '?query=abc',
10 state: { detail: 'some_value' }
11 });
12 };
13
14};
15
16export default FirstPage;
17
18
19
1import { useHistory } from "react-router-dom";
2
3const FirstPage = props => {
4 let history = useHistory();
5
6 const someEventHandler = event => {
7 history.push({
8 pathname: '/secondpage',
9 search: '?query=abc',
10 state: { detail: 'some_value' }
11 });
12 };
13
14};
15
16export default FirstPage;