历史推送与React Router的堆叠

问题描述

我正在尝试使用react-router做一些简单的路由,但是遇到了一个我从未遇到过的问题... 我正在尝试使用可与路由切换保持一致的布局进行路由,所以我有类似以下内容

        <Layout>
          <Switch>
            <Route path="/" exact render={() => <Redirect to="/vouchers/fixes" />} />
            <Route exact path="/vouchers/fixes" component={Vouchers} />
            <Route exact path="/vouchers/reportes" component={Vouchers} />
            <Route exact path="/recibos/fixes" component={NotFound} />
            <Route exact path="/recibos/reportes" component={NotFound} />
          </Switch>
        </Layout>
      </browserRouter>

在布局中,我有重定向

        <List>
          <ListItem button onClick={() => history.push("vouchers/fixes")}>
            <ListItemIcon>
              <InBoxIcon />
            </ListItemIcon>
            <ListItemText primary="Vouchers" />
          </ListItem>
          <ListItem button onClick={() => history.push("recibos/fixes")}>
            <ListItemIcon>
              <MailIcon />
            </ListItemIcon>
            <ListItemText primary="Recibos" />
          </ListItem>

因此,当我尝试在路线之间导航而不是仅用新路线替换URL时,它们会被串联起来

http://localhost:3000/vouchers/recibos/vouchers/recibos/vouchers/recibos/vouchers/recibos/vouchers/vouchers/vouchers/vouchers/recibos/recibos/fixes

每次点击都会添加一个...我试图摆脱/并通过将其称为凭单和收据来简化路线,并且可以正常工作...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)