路由但不能从反应JS反应路由器

路由但不能从反应JS反应路由器

问题描述:

在我的WebPack,应用程序的入口点设置为index.js路由但不能从反应JS反应路由器

entry: { 
    app: [ 
     'react-hot-loader/patch', 
     './client/index.js' 
    ] 

在节点JS,对于路径/在我的申请,我路由到index.htmlroutes.js使用服务器端:

app.route('/*') 
    .get((req, res) => { 
    res.sendFile(path.resolve(`${app.get('appPath')}/index.html`)); 
    }); 

上面的代码可以理解提供的index.html。

但是如果我想让我的应用程序路由使用React-router进行初始化呢?

index.html得到渲染,但我没有看到index.js得到初始化所有。它被定义为webpack中的入口点,所以应该发生,对吗?

问题:要有阵营路由初始化前应该工作,一旦流量到达index.js

routes.js客户端文件夹中看起来是这样的:

import React from 'react'; 
import {Route, IndexRoute} from 'react-router'; 
import About from './components/About/About'; 
import Header from './components/Header/Header'; 
import Outlet from './components/Home/SelectOutlet'; 

console.log("routes file client") 

    export default (
     <Route path="/" component={Header}> 
     <IndexRoute component={Outlet}/> 
     <Route path="about" component={Footer}/> 
     </Route> 
    ); 

index.js

import 'babel-polyfill'; //certain functions like array.from , set, map can't be transpiled by babel so ue poyfill for that 
import React from 'react'; 
import { render } from 'react-dom'; 
import { Router, browserHistory } from 'react-router'; 
import routes from './routes'; 
//import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; //webpack can import CSS files too 
import './styles/styles.css'; 

render((
    <Router history={browserHistory} routes={routes}/>), 
    document.getElementById('app') 
); 

console.log("In index js render ") 

控制台index.jsroutes.js永远不会得到安慰和应用程序只是起到index.html因为快递路由

我的WebPack文件就是从这里取:https://github.com/Hashnode/mern-starter

,但我没有看到bundle.js得到与NPM启动命令创建任意位置。

编辑: 错误截图: 画面1: error message

当我点击此错误消息:

我得到的所有的HTML中JS内容:

<!DOCTYPE html> 
<html> 
    <head> 
     <title> 
      ABC 
     </title> 
    </head> 
    <body> 
     <h1> XYZ</h1> 
     <div id="app"></div> 
     <script src="index.js"></script> 

    </body> 
</html> 

那么...你是否包括

<script src="index.js"></script> 

in your index.html?...

+0

是的,我试过了。我有意想不到的符号 gags

+0

您一定需要在index.html中包含该脚本,但您需要修复该错误。你能对你的错误更具体吗?或者显示它的屏幕截图 – Kevin

+0

嘿,当然,更新了问题 – gags