Reactstrap或React-router v4不会重定向以进行部分地址链接更改

问题描述 投票:1回答:1

在我的标题中,

<NavItem>
   <NavLink tag={Link} to="/template/editor">New Template</NavLink>
</NavItem>

在我的路由器页面中

<BrowserRouter>
  <div className="container-fluid">
    <Header />
    <section className="page-content">
      <Route exact path="/" component={HomePage} />
      <Route exact path="/template/editor/:id?" component={Authenticate(EditorPage)} />
    </section>
  </div>
</BrowserRouter>

如果我在我的主页上(/)并单击新模板链接(/ template / editor),它会将我重定向到New Template页面。但是,如果我在(/ template / editor / 3)上,并单击“新建模板链接”(/ template / editor),则地址栏会更新,但页面不会被路由。我确定我错过了一些简单但我无法弄清楚的东西。

javascript reactjs bootstrap-4 react-router-v4 reactstrap
1个回答
1
投票

我不确定是什么问题,但我相信你试图做的是:

<BrowserRouter>
  <div className="container-fluid">
    <Header />
    <section className="page-content">
      <Switch>
        <Route exact path="/" component={HomePage} />
        <Route path="/template/editor/:id?" component={Authenticate(EditorPage)} />
      </Switch>
    </section>
  </div>
</BrowserRouter>

(注意我使用了Switch包中的react-router-dom

另外,你说你正在使用react-redux有一个已知的问题,视图没有更新。 Look at this question

© www.soinside.com 2019 - 2024. All rights reserved.