【发布时间】:2016-03-06 22:15:57
【问题描述】:
我的路线已定义,当我导航到products/new 时,工作正常,但如果刷新页面,他products/new 没有进入,他返回意外令牌。
路线配置。
<Router history={createBrowserHistory()}>
<Route path="/" component={Layout}>
<IndexRoute component={Home} />
<Route path="produtos/novo" component={ProductsNew}/>
<Route path="produtos" component={Products} />
</Route>
【问题讨论】:
-
您需要设置 .htaccess 或虚拟主机(如果您使用的是 Apache)将所有请求指向您的应用所在的索引页面。
-
这个错误只出现在``` products/new ```,其他页面在刷新时正常。我的服务器是 node + express。
-
您提供的代码中没有为
products/new设置路由。这可能是原因,虽然我需要更多信息来帮助你...... -
这是我的服务器:
const express = require('express') const path = require('path') const port = process.env.PORT || 8000 const app = express() // serve static assets normally app.use(express.static(__dirname + '/public')) // handle every other route with index.html, which will contain // a script tag to your application's JavaScript file(s). app.get('*', function (request, response){ response.sendFile(path.resolve(__dirname, 'public', 'index.html')) }) app.listen(port) console.log("server started on port " + port) -
当您导航到
produtos/novo时会发生什么?
标签: reactjs