2016-07-02 4 views
1

React Routeで次のことを行うことはできますか?リアクションルートは、サブルートを別のモジュールに移動しますか?

メイン

<Routes handler={App}> 
    <Profile path="profile" /> 
    <Explore path="explore" /> 
    </Routes> 

プロフィール

<Route> 
     <Route name="dashboard" handler={ProfileDashboard} /> 
     <Route name="repos" handler={ProfileRepos} /> 
    </Route> 

<Route> 
     <Route name="home" handler={ExploreHome} /> 
     <Route name="showcase" handler={ExploreShowcase} /> 
    </Route> 
+0

私の質問はなぜあなたがそれをしたいと思いますか? –

答えて

1

あなたがルータに反応してそれを達成することができます探検! :)

しかし、私はあなたのルートを設定するには、「プレーンルート」の方法を、それをチェックアウトすることができことをお勧め:

これを使用して

https://github.com/reactjs/react-router/blob/master/docs/guides/RouteConfiguration.md#configuration-with-plain-routes

、あなたはroutesオブジェクトで作業を開始します、とのことができます。ちょうどrequire別のルートとそれらの組み合わせに基づいてルートを作成します。そのような何か:

const routes = { 
    path: '/', 
    component: App, 
    childRoutes: [ 
     require('./profile'), 
     require('./explore') 
    ] 
} 

次に、あなたのprofile.js(あなたがexplore.jsに同じことを行うことができます)ファイルで、あなたがそのようなものがあります:

/* Import the ProfileDashboard and ProfileRepos here */ 

const profileRoutes = { 
    path: 'profile', 
    childRoutes: [{ 
     path: 'dashboard', 
     component: ProfileDashboard 
    }, { 
     path: 'repos', 
     component: ProfileRepos 
    }] 
}; 

をそして、あなたはあなたが望むものを達成することができますこの方法。

あなたが本当にプレーンなルートを使用できない場合は、あなたがそのような何かがあります。例えば、

<Route path="/" component={App}> 
    { require('./profile') } 
    { require('./explore') } 
</Route> 

そして、あなたのprofile.jsを:

module.exports = (
    <Route path="profile"> 
     <Route path="dashboard" component={ProfileDashboard} /> 
     <Route path="dashboard" component={ProfileRepos} /> 
    </Route> 
); 

私はルータに反応かわかりませんバージョンを使用していますが、どのバージョンでもそれを達成できますが、提案として、最新バージョンを使用してみてください。それはクールなものをたくさん扱うので。

希望すると助かります!

+0

これはあなた自身で試しましたか?私はこれのようなものを試しましたが、うまくいきませんでした! –

+0

はい、うまくいきました。どの反応/反応ルータバージョンを使用していますか? –

+0

うん、ちょうどそれをありがとうhttps://github.com/alikor/spike-react-routes –

関連する問題