React RouterのURLパラメータ機能を使用できないため、洞察力が役立ちます。私は 'react-router-dom'を 'react-router'の代わりに使用しようとしましたが、この男が取得しているエラーを受け取ります:https://github.com/ReactTraining/react-router/issues/1799リアクタルータのURLパラメータが機能しない
私がlocalhost:8000を実行すると、アプリケーションが動作します。私がlocalhost:8000/123に行くと、ブラウザはindex.htmlをそのまま返信します。 ExpressはReactを妨害していますか?
import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import Routes from './shared/components/Routes';
const ROOT_ELEMENT = 'app';
ReactDOM.render((
<Router history={browserHistory}>
{Routes}
</Router>
), document.getElementById(ROOT_ELEMENT));
マイroutes.js:
import { Route, IndexRoute, Link } from 'react-router';
import App from './App';
import HomePage from '../../pages/home/page';
import AboutPage from '../../pages/about/page';
const Child = ({ match }) => (
<div>
<h3>ID: {match.params.id}</h3>
</div>
)
export default (
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
{/* <Route path="about" component={AboutPage} /> */}
<Route path="/:id" component={Child} />
</Route>
);
マイホームコンポーネント
app.get('*', function response(req, res) {
res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html')));
res.end();
});
はここに私のmain.jsです:エクスプレスでは、私が持っているすべては、以下のとおりです。別のファイルでこのように定義されています(すべてのインポートとライフサイクルを省きました)電子機能):要求されたよう
export default React.createClass({
render: function() {
{* bunch of JSX goes here *}
}
});
、私ののindex.htmlファイル:HTMLが原因で私ののWebPACKの設定のスクリプトタグとしてバンドルを持っていない
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Consent Form</title>
<meta name="description" content="Privacy Consent Webform">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--Google Material Design Icons-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<div id="app"></div>
</body>
</html>
(バンドルが注入されます!)(次のコードは設定の一部です)
entry: [
'webpack-hot-middleware/client',
'bootstrap-loader',
path.join(__dirname, 'src/main.js')
],
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name].js',
publicPath: '/'
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.tpl.html',
inject: 'body',
filename: 'index.html'
})
あなたの問題は、ご使用のスクリプトタグを使用してindex.htmlにバンドルを含めることができます。確かにそれを投稿してもいいですか? –
@promisified sure! – ykadaru
静的ファイルサーバーの設定を含めることはできますか?クライアントコンソールでエラーが発生していますか? –