Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react路由器只去索引路由_Reactjs_React Router - Fatal编程技术网

Reactjs react路由器只去索引路由

Reactjs react路由器只去索引路由,reactjs,react-router,Reactjs,React Router,我在react中遇到了这样一种情况:我的应用程序可以识别索引路由。我的app.js中的代码如下所示: 从“React”导入React 从'react dom'导入{render} 从“react Router”导入{Router,Route,Link,IndexRoute} 类应用程序扩展了React.Component{ render(){ 返回( 你好,有应用程序吗 ); } } 类关于扩展React.Component{ render(){ 返回( 你好,关于 ); } } 类错误扩

我在react中遇到了这样一种情况:我的应用程序可以识别索引路由。我的app.js中的代码如下所示:

从“React”导入React
从'react dom'导入{render}
从“react Router”导入{Router,Route,Link,IndexRoute}
类应用程序扩展了React.Component{
render(){
返回(
你好,有应用程序吗
);
}
}   
类关于扩展React.Component{
render(){
返回(
你好,关于
);
}
}
类错误扩展了React.Component{
render(){
返回(
你好,有错误吗
);
}
}
反应((
),document.body)
我查看了一些类似的链接:

但这些并没有推动我前进。我正在运行一台express服务器,我在那里也有一条路线:

app.use(ecstatic({ root: __dirname + '/public', handleError:true }));
app.get('/', function(request, response){
    response.sendfile("./public/index.html");
});
无论是否使用
应用程序。get(“/”…
我都遇到了同样的问题。同样值得注意的是,我也尝试过这种方式:但我的路线也没有这样做。我将用4天的时间对这个问题进行无休止的研究,希望你们中的一位能够为我指明正确的方向

package.json:

"dependencies": {
    "body-parser": "~1.14.1",
    "browserify": "^10.2.6",
    "cors": "^2.7.1",
    "ecstatic": "~0.8.0",
    "express": "~4.0.0",
    "history": "^1.13.1",
    "mongoose": "~4.2.6",
    "react": "~0.13.3",
    "react-dom": "^0.14.3",
    "react-router": "^1.0.0",
    "reactify": "^1.1.1",
    "socket.io": "^1.3.7",
    "uglify-js": "^2.4.24",
    "watchify": "^3.2.3"
  },
  "license": "public domain",
  "devDependencies": {
    "babelify": "^6.1.2"
  }

使您的路线看起来像:


您缺少的另一部分是应用程序组件中的
{this.props.children}
,嵌套路由组件应该安装在该组件中

查看使用NotFound路由的示例

在您的服务器上,我会将所有内容重定向到index.html,而不仅仅是
/

app.get('*',函数(请求,响应){
response.sendfile(“./public/index.html”);
});

感谢您的回复,我仍然收到同样的问题。我转到
http://localhost:8000/
然后将一些参数广告到URL
http://localhost:8000/#/?_k=3z6ymz
然后我被带到我的索引路径页面,页面上写着
你好那里的应用程序
,但是当我尝试去
http://localhost:8000/about
它将我带到错误页面(404.html)。如果我在server.js中将handleError设置为false,它只会简单地说无法获取关于路由的
。当我转到
http://localhost:8000/#/about
我又看到了
Hello There应用程序
带有额外参数
http://localhost:8000/#/about?_k=de8di9
非常感谢您在这一点上的帮助。这正是我想要的是的。我在我的路线中添加了
*
,然后添加了
{this.props.children}
。另外,我的路线逻辑有点落后,所以谢谢你的澄清!