LoginSignup
6
6

More than 5 years have passed since last update.

React Routerでパスに直接アクセスすると404エラーがでたときの対応

Last updated at Posted at 2015-06-01

概要

React Routerでパスに直接アクセスすると404エラーが発生しました。

考えたこと

サーバーサイドで、毎回Router.runを走らせる必要がある説。

問題

  • Node.jsじゃないとだめ
  • Angular.jsではできていたのに何故できないのか

解決策

Router.run(Routes, Router.HistoryLocation, function (Handler) {
  React.render(<Handler/>, content);
});

Router.run(Routes, Router.HashLocation, function (Handler) {
  React.render(<Handler/>, content);
});

にして解決。

React Router Documentationには以下のようにある。

This is the default location used in Router.run because it will always work, though we recommend you configure your server and use HistoryLocation.

HistoryLocationはサーバーの設定が必要だそうです。

6
6
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
6
6