反应嵌套路线不加载组件

时间:2020-04-29 12:30:35

标签: reactjs routes react-router

由于某种原因,这种简单的设置似乎不起作用,我忘记了什么?

import React from "react";
import { Route, Link } from "react-router-dom";


const Account = () => {
    return (
        <div>
            Account
        go back to <Link to="/menu">menu</Link>
        </div>
    )
}
const Book = () => {
    return (
        <div>
            Book
        go back to <Link to="/menu">menu</Link>
        </div>)
}
const Menu = props => {
    return (
        <div>
            <Route path="/menu" render={() => {
                return (
                    <div>
                        home
                        <br /><Link to="menu/account">account</Link>
                        <br /><Link to="menu/book">book</Link>
                    </div>
                )
            }} />
            <Route exact path="/menu/account" component={Account} />
            <Route exact path="/menu/book" component={Book} />
        </div>
    )
}


export default Menu;

这是第二个问题,在我的更大项目中,嵌套的路由有效,但仅当从“ Link tag”元素调用该路由时才起作用,而在从刷新或地址栏调用时中断(CSS疯了)

谢谢。

0 个答案:

没有答案