40
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

React Router の"Switch"や"exact" が使用できない時の対処法

Last updated at Posted at 2021-11-06

#参考

正確な詳しい情報を知りたい方はこちらを参照してください

エラー

Module '"react-router-dom"' has no exported member 'Switch'.
型 '{ children: element; exact: true; path: string; }' を型 'intrinsicattributes & (pathrouteprops | layoutrouteprops | indexrouteprops)' に割り当てることはできません。 プロパティ 'exact' は型 'intrinsicattributes & (pathrouteprops | layoutrouteprops | indexrouteprops)' に存在しません。

#原因
React Router v6を使っている場合に起こるエラー

#解決策

1. 記述を変える

  • "Switch"を"Routes"に変える
  • exactを使わない

2. バージョンを下げる

npm install react-router-dom@5
40
19
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
40
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?