如何从root更改localhost登录页面?

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

所以我有2条路线,分别是/first/second。当我去http://localhost:3000/时,我看不到任何东西,因为我根本没有任何东西(/)。所以我想知道是否有可能使http://localhost:3000/直接重定向到http://localhost:3000/review或有没有其他方法使它成为可能?

<Router history={history}>
    <div>
        <Route
            path="/first"
            render={() => <myComponent />}
            exact
        />
        <Route
            path="/second"
            render={() => <secondComponent />}
        />
    </div>
/>
reactjs react-router react-router-v4 react-router-dom
1个回答
0
投票

必须在Route之后添加重定向,并将所有内容包装在Switch中。

      <Router history={history}>
        <Switch>
          <Route
            path="/review"
            render={() => <RateReviewStep cancelRateReview={this.cancelRateReview} />}
            exact
          />
          <Route
            path="/confirm"
            render={() => <RateConfirmationStep model={model} fields={fields} />}
          />
          <Redirect from="/" to="review" />
        </Switch>
      </Router>
© www.soinside.com 2019 - 2024. All rights reserved.