鍍金池/ 問答/HTML5  HTML/ react router4.0路由嵌套

react router4.0路由嵌套

先上代碼為敬


const routes = [
    {
        path: '/',
        exact: true,
        component: Main,
    },
    {
        path: '/company',
        // exact: true,
        component: CompanyIntroduce,
        routes:[
            {
                path: '/company/introduce',
                exact: true,
                component: CompanyManagement,
            },
            {
                path: '/company/management',
                exact: true,
                component: CompanyManagement,
            },
        ]
    },
];

const router = (
    <Router history={history}>
        <AppContainer history={history}>
            <Switch>
                {routes.map((route, i) => (
                    <ExtendRoute key={i} {...route} />
                ))}
                <Route component={NoMatchContainer} />
            </Switch>
        </AppContainer>
    </Router>
);

export default router;

想做一個嵌套路由,訪問/company/company/introduce都指向CompanyIntroduce 組件,而訪問/company/management指向CompanyManagement 組件,可是事實結果就是不管我,訪問/company也好,訪問/company/introduce也好,還是訪問/company/management也好,通通指向到CompanyIntroduce 組件,react router4.0版本已經(jīng)看了 兩三天了,愣是沒看懂它的用法,和vue的路由比較起來,真的是難用難理解,求會的大佬幫忙看一下問題在哪,不勝感激??!

回答
編輯回答
懶豬

文檔里有介紹,出現(xiàn)這種現(xiàn)象的原因就是沒有使用<Switch>包裹。
我們有現(xiàn)成的項目,你自己參考下吧。
initial dav

2017年11月4日 21:54