0

我已经在 api 服务中发布了 UI,但我想从“/”开始 url。但它以http://localhost:8090/UI/的形式出现。问题是在路由配置中我已经设置了路由为:-

ReactDOM.render((
  <Router history={browserHistory}>
   <Route path="/" component={Login}/>
   <Route path="main" component={main}>
     <IndexRoute component={Home} />
    <Route path = "/Accession" component = {Home} />
     <Route path="/contact" component={Contact}/>
 </Route>
  </Router>
), document.getElementById('App'));

错误:/UI/ 未在路由中定义。要解决此问题,我必须将路由更改为Route path="/UI/" 。如何将“/”设置为初始路径?

4

2 回答 2

0

对我来说,以下代码有效:-

import { Router,Route,IndexRoute, hashHistory, Link } from '../node_modules/react-router';

ReactDOM.render((
  <Router history={hashHistory}>
   <Route path="/" component={Login}/>
   <Route path="/main" component={main}>
     <IndexRoute component={Home} />
    <Route path = "/Accession" component = {Home} />
     <Route path="/contact" component={Contact}/>
 </Route>
  </Router>
), document.getElementById('App'));

所以代替 browserHistory 使用 hashHistory

于 2016-12-02T12:18:44.593 回答
0

尝试这个:

 ReactDOM.render((
 <Router history={browserHistory} routes={
  [<Route path = '/' component={Login}>
   <Route path="main" component={main}>
     <IndexRoute component={Home} />
     <Route path = "/Accession" component = {Home} />
     <Route path="/contact" component={Contact}/>
   </Route>
</Route>]} />

), document.getElementById('App'));
于 2016-12-01T10:51:44.613 回答