2016-08-25 131 views
0

我想我使用非常基本的反应路由器实现时遇到了问题。 当我加载我的“localhost:8080/dist /”,它工作,加载在App上导入的头部组件,并正确加载IndexRoute,但是当我尝试访问“localhost:8080/dist/FPDV0200“”localhost:8080/dist/FPDV0400“它dosnt工作。任何线索?反应路线无法正常工作

app.component.tsx

import * as React from 'react'; 

import Header from '../header/header.component'; 

class App extends React.Component<any, any> { 
    render() { 
     return (
      <div id="app"> 
       <Header /> 
       <div> 
        {this.props.children} 
       </div> 
      </div> 
     ); 
    } 
} 

export default App; 

app.component.tsx

import * as React from 'react'; 
import { Router, hashHistory, Route, IndexRoute } from 'react-router'; 

import App from '../components/structure/app/app.component'; 
import Home from '../pages/home/home'; 
import FPDV0200 from '../pages/FPDV0200/FPDV0200'; 
import FPDV0400 from '../pages/FPDV0400/FPDV0400'; 

const routes = (
<Router history={hashHistory}> 
    <Route path="/" component={App}> 
     <IndexRoute component={Home}/> 
     <Route path="FPDV0200" component={FPDV0200}/> 
     <Route path="FPDV0400" component={FPDV0400}/> 
    </Route> 
</Router> 
); 

export default routes; 
+1

你要确保你的服务器给你的index.html不管你求什么路径?没有散​​列,你需要服务器来支持它。如果您不想对服务器执行任何操作,请尝试使用哈希值。 – goldbullet

+0

尝试在您的主页中添加一些<链接组件。点击此组件并将浏览器网址与您预期的网址进行比较。 – degr

+0

我使用浏览器同步作为本地开发的服务器,我现在做了一项研究,发现我需要在浏览器同步选项中指定'connect-history-api-fallback',但它仍然无法工作。 。我是localhost中的服务器,并使用/ dist,因为我的依赖关系文件位于根目录中。@goldbullet –

回答

1

localhost:8080/dist/FPDV0200 - 这个网址应使用browserHistory的情况下工作。

您使用hashHistory,所以您的网址应该是这样的

localhost:8080/dist#FPDV0200 
+0

第二个使用#真的工作,但浏览器历史dosnt,我使用浏览器同步服务的应用程序,阅读一些东西tryed应用'connect-history-api-fallback',但仍然不能按预期工作... –

+0

Actualy我在这里找到了解决方案:https://github.com/BrowserSync/browser-sync/issues/204 并使用文档和借鉴从这里https://github.com/bripkens/connect-history-api-fallback –