2017-02-22 4 views
1

私はサブルートを作成できる理由を知っているかもしれません 私のコード。React-Routerはサブルートを作成できません

<Provider store={store}> 
    <Router history={history}> 
     <Route path="/" component={Main} > 
     <IndexRoute component={Home} /> 
     <Route path="performance" component={Performance} /> 
     <Route path="home" component={Home} > 
      <Route path="alert" component={Performance} /> 
     </Route> 
     </Route> 
    </Router> 
</Provider> 

// ... 
// imports 
import Main from './Main' 
import Performance from './performance/PerformanceComponent' 
import Home from './home/HomeComponent' 

import {Router, Route, IndexRoute} from 'react-router' 
import {Provider} from 'react-redux' 

私はこのアドレスに行くことができない - > /ホーム/警告

そして、私は特別なエラー

を持って、私は間違ったアドレスを書く場合、私は意味

alert:11 GET http://0.0.0.0:3001/home/css/style.css 
alert:12 GET ...home/css/home.css 
alert:13 GET ...home/css/detailsView.css 
alert:26 GET ...home/bundle.tvc.js 

コンソールでこのエラーを持っています

Warning: [react-router] Location "/homealert" did not match any routes

私はそれをどのように修正するべきかわかりません。前もって感謝します!

+0

あなたは '警告に/ホーム/アラートの結果を使用していることを言っている:11 GET http://0.0.0.0:3001/home/css/style.css。コンソールでは 'warning:[react-router] Location/homealert"はどのルートにも一致しませんでした。 –

+0

はい。それは非常に奇妙です –

答えて

1

コンポーネントをレンダリングする場合は、/home/alertにします。一致するそれぞれのパスに完全なパスを指定する必要があります。Route

<Route path="/" component={Main} > 
    <IndexRoute component={Home} /> 
    <Route path="/performance" component={Performance} /> 
    <Route path="/home" component={Home} > 
     <Route path="/home/alert" component={Performance} /> 
    </Route> 
    </Route> 

ネスティングルートは、パスではなくコンポーネントに適用されます。アプリは/home/alertのために次のようにレンダリングされます:

<Main> 
    <Home> 
    <Performance> 
関連する問題