react-router-dom失效

发布于 2022-09-06 09:19:25 字数 1987 浏览 7 评论 0

本想加个 nprogress 个,但是这里套上去之后 我的的路由组件的exact属性似乎全部不起作用了为什么?
主要代码如下:


    class ProgressLoading extends React.Component {
        componentWillMount() {
            nprogress.start()
        }
    
        componentDidMount() {
            nprogress.done()
        }
    
        render() {
            return (
                <Route exact {...this.props} />
            )
        }
    }
    
    const routerArray = [
        { path: '/logout', component: Logout },
        { path: '/index', component: IndexPage },
        { path: '/hotel', component: HotelList },
        { path: '/hotel/manage', component: HotelManage },
        { path: '/hotel/manage/roomType', component: RoomType },
        { path: '/hotel/manage/roomAdd', component: RoomAdd },
        { path: '/hotel/manage/roomPrice', component: RoomPrice },
        { path: '/customer', component: Customer },
        { path: '/customer/detail/:id', component: CustomerDetail },
        { path: '/replacement', component: Replacement },
        { path: '/replacement/manage', component: ReplacementManage },
        { path: '/replacement/add', component: ReplacementAdd },
        { path: '/replacement/manage/detail/:id', component: ReplacementDetail },
        { path: '/replacement/manage/edit/:id', component: ReplacementAdd },
        { path: '/order', component: Order },
        { path: '/order/detail', component: OrderDetail },
        { path: '/invoice', component: InvoiceTable },
        { path: '/invoice/:id', component: InvoiceManage },
        { path: '/logout', component: Logout },
        { path: '/logout', component: Logout }
    ]
    
    const routerList = routerArray.map((props, i) => {
        return <ProgressLoading {...props} key={i} />
    });
    
    const MainRouter = () => (
    
        <Switch>
            {
                routerList
            }
            <Redirect from='*' to='/404' />
        </Switch>
    )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文