LoginSignup
0
1

More than 1 year has passed since last update.

【React】遷移先画面へ値を受け渡す

Posted at

react-routerの機能を使用する方法

遷移先へ値を受け渡す方法

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

const history = useHistory();

history.push({
  pathname: '/foo',
  state: { bar: 'bar' }
});

遷移元から受け取った値を使用する方法

import { useHistory, useParams } from 'react-router-dom';

const location = useLocation<{ bar: string }>();

location.state.bar;
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1