[英]react-router v2.0 browserHistory not working
Currently using react-route v2.0. 当前使用react-route v2.0。
I am sure I am over looking something but I am able to get hashHistory working but when implementing browserHistory I get a 404 error msg as I am trying to remove hashHistory in the url and as well would like to know a work around for production. 我确定我正在寻找一些东西,但是我能够使hashHistory工作,但是在实现browserHistory时,由于我试图删除url中的hashHistory并得到一个404错误消息,因此我也想知道如何解决生产问题。
I been pulling out my hair all afternoon and can't seem to see where I am going wrong. 我整个下午都在拔头发,似乎看不到我要去哪里。
app/App.jsx 应用程序/ App.jsx
var React = require('react');
var ReactDom = require('react-dom');
var Router = require('react-router').Router;
var routes = require('./config/routes');
var browserHistory = require('react-router').browserHistory;
ReactDom.render(
<Router history={browserHistory}>{routes}</Router>,
document.getElementById('app')
);
app/config/routes.jsx 应用程序/配置/ routes.jsx
var React = require('react');
var Main = require('../components/Main');
var Home = require('../components/Home');
var Profile = require('../components/Profile');
var Router = require('react-router');
var Route = Router.Route;
var IndexRoute = Router.IndexRoute;
module.exports = (
<Route path="/" component={Main}>
<Route path="profile/:username" component={Profile} />
<IndexRoute component={Home} />
</Route>
);
Here is a repo that I am working on https://github.com/SOSANA/React.JS-Tutorials-and-Things/tree/master/github-notetaker/04-state-and-props 这是我正在使用的回购协议https://github.com/SOSANA/React.JS-Tutorials-and-Things/tree/master/github-notetaker/04-state-and-props
Hope someone can help 希望有人能帮忙
您需要在script标记中使用相对于根(或绝对)的URL,否则应用程序最终会在目录中请求脚本,并且服务器将响应(全部)html文件。
<script src="/bundle.js"></script>
You need to additionally configure your server when using browserHistory
to serve the appropriate resource on the initial page load. 使用
browserHistory
在初始页面加载时提供适当的资源时,您需要另外配置服务器。
For more details see https://github.com/rackt/react-router/blob/master/docs/guides/basics/Histories.md#configuring-your-server . 有关更多详细信息,请参见https://github.com/rackt/react-router/blob/master/docs/guides/basics/Histories.md#configuring-your-server 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.