5
1

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-domで"Cannot destructure property 'basename' of ~ as it is null."というエラーが出る

Posted at

発生したエラー

react-router-domのLinkを使おうとしたら、
以下のようなエラーが出ました。

Cannot destructure property 'basename' of 'react__WEBPACK_IMPORTED_MODULE_0__.useContext(...)' as it is null.
TypeError: Cannot destructure property 'basename' of 'react__WEBPACK_IMPORTED_MODULE_0__.useContext(...)' as it is null.

解決策

React Routerによるルーティングの設定が行えるようにするには、
BrowserRouterAppを囲む必要があったようです。

import { BrowserRouter } from 'react-router-dom'

render(
  <BrowserRouter>
    <App />
  </BrowserRouter>
)

注意

BrowserRouterは、Reactプロジェクトの中で一度しか使えません、
また、React RouterはBrowserRouterの中でしか使えないため気をつけましょう。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?