1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

Posted at

はじめに

Reactでルーティングを作成しようとしていた時に、タイトルのエラーに遭遇したので解決策をまとめました。

問題

import { BrowserRouter, Link, Switch, Route } from "react-router-dom";

import文の中の Switchが問題だった。

解決方法

react Routeバージョン5以前では、Reactアプリのルートをラップするのに Switch コンポーネントが使用されていました。
問題が起きたのはバージョン6なので、React Routerバージョン6では Switch の代わりに Routes コンポーネントに置き換えられています。

imprt { Routes } from 'react-router-dom';

おわりに

焦らずエラー文を解釈し、バージョン差分には気を付けましょう。

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?