3
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 5 years have passed since last update.

[React][webpack]テスト環境でルートパス以外表示できない時の対処法

Last updated at Posted at 2019-10-01

環境

    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "webpack": "^4.41.0",
    "webpack-cli": "^3.3.9",
    "webpack-dev-server": "^3.8.1"

現象1

/ 以外にアクセスすると 404 Not Found になる。

解決法1

webpack.config.js に以下のように書き足す。

webpack.config.js
:
module.exports = {
    :
    devServer: {
        historyApiFallback: true,
    },
    :
}

現象2

ルーターにサブディレクトリを指定し、サブディレクトリに直接アクセスすると、 bundle.js が 404 Not Found になって真っ白になる。

解決法2

webpack.config.jsoutputpublicPath: '/' を書き足す。

webpack.config.js
:
module.exports = {
    :
    output: {
        :
        publicPath: '/',
    },
    :
}

参考

3
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
3
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?