有没有可能有不嵌套的路由?



我正在玩reactjs路由。在所有的例子中,路由总是嵌套的,比如

<Route path="/" handler={App} >
    <Route name="about" handler={About} />
    <Route name="contact" handler={Contact} />
</Route> 

是否可能有简单的非嵌套路由,如下所示?

 <Route path="/" handler={App} />
 <Route name="about" handler={About} />
 <Route name="contact" handler={Contact} />

更新:

var routes = (
    <Route name="root" handler={Root}>
        <Route path="/" handler={Home} />
        <Route path="/home" handler={Home} />
        <Route path="/about" handler={About} />
        <Route path="/projects" handler={Projects} />
        <Route path="/contact" handler={Contact} />
    </Route> 
);

奇怪的问题,根据下面的答案建议更新到这个。name不再工作,只有path工作?我不得不更新路线。任何想法?

这似乎是不可能的。但是我使用了一个技巧来模拟这样的行为:

var Routes = (
    <Route name="root" handler={Root}>
        <Route name="checkout" path="/checkout/:step" handler={Checkout}/>
        <Route name="application" path="/" handler={Application}>
            <DefaultRoute handler={Promo}/>
            <Route name="agreement" handler={Agreement}/>
            <Route name="policy" handler={Policy}/>
            <Route name="how-it-works" handler={Brief}/>
            <Route name="login" handler={Login}/>
            <Route name="faq" handler={Faq}/>
            ...
            <NotFoundRoute handler={NotFound}/>
        </Route>
        <NotFoundRoute handler={NotFound}/>
    </Route>
);

其中Root只是一个带有body标签的基本html页面,其内容由路由处理程序呈现。

这里我需要一个结帐页面与不同的页面布局,但在相同的路径段级别的协议或登录页面。

最新更新