React路由器渲染组件在主组件外部

时间:2016-07-24 16:44:17

标签: reactjs react-router

我希望在根目录下渲染一个SINGLE组件而不渲染额外的组件,例如Nav。

这是我的路线档案:

import React from 'react';
import { Route, IndexRoute } from 'react-router';

import Gatekeeper from './Gatekeeper';

import Home from './components/Pages/Home';
import StrainGrid from './components/Strains/StrainGrid';
import Single from './components/Strains/Single';
import Event from './components/Events/Event';
import Faqs from './components/Pages/Faqs';
import Login from './containers/Patients/Login';
import NewPatient from './containers/Patients/NewPatient';
import Billing from './containers/Patients/Billing';
import AdminDashboard from './containers/Admin/Dashboard';
import AdminAddEditUser from './containers/Admin/AddEditUser';
import PatientForm from './containers/Patients/Form';
import LandingPage from './components/Pages/LandingPage'

module.exports =(
    <Route path="/" component={Gatekeeper}>
        <IndexRoute component={Home}></IndexRoute>
        <Route path='/view/:postId' component={Single}></Route>
        <Route path='/events/:eventId' component={Event}></Route>
        <Route path='/strainguide' component={StrainGrid}></Route>
        <Route path='/faqs' component={Faqs}></Route>
        <Route path='/login' component={Login}></Route>
        <Route path='/signup' component={NewPatient}></Route>
        <Route path='/patient/billing' component={Billing}></Route>
        <Route path='/admin' component={AdminDashboard}></Route>
        <Route path='/admin/addEdit' component={AdminAddEditUser}></Route>
        <Route path='/patient/form/:patientID' component={PatientForm}></Route>
        <Route path="*" component={Home} />
    </Route>
)

所以我试图渲染&#34; LandingPage&#34;组件作为IndexRoute,但当然得到从&#34; Gatekeeper&#34;中导入的所有组件。成分

如何使索引导致LandingPage组件。但是当你转到/ app它将呈现GateKeeper组件和所有导入等...

1 个答案:

答案 0 :(得分:0)

也许是嵌套路线? import pandas as pd df = pd.DataFrame([[0] * len(Nom)] * len(Nom), Nom, Nom) print(df) - <Route path="/" component={Gatekeeper}>在这种情况下使用类似于页面的布局,包括Gatekeeper

您必须在路线中添加第二层,如下所示:

LandingPage