react-router重新加载页面重定向到主页

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

[当我尝试重新加载子页面应用程序时,将我重定向到主页。当我输入浏览器子页面(例如“ / about”)时,应用会将我重定向到主页。这是我在App.js中的路由器组件。附言:我在React中使用箭头功能。

<Router>
        <Header />
        <Container history={props.history}>
          <Route exact path="/" component={SelectLogin} />
          <Route path="/selectlogin" component={SelectLogin} />
          <Route path="/about" component={About} />
          <Route path="/register" component={RegisterPanel} />
          <Route path="/addcomment" component={AddComment} />
          <Route path="/findposts" component={FindPosts} />
          <Route path="/lostposts" component={LostPosts} />
          <Route path="/posts" component={Posts} />
          <Route path="/lostpost" component={LostPost} />
          <Route path="/findrequest" component={FindRequest} />
          <Route path="/lostrequest" component={LostRequest} />
          <Route path="/requestsummary" component={Summary} />
          <Route path="/logincode" component={LoginCodePanel} />
          <Route path="/logindata" component={LoginDataPanel} />
          <Route path="/adminpanel" component={AdminPanel} />
          <Route path="/editprofile" component={EditProfile} />
          <Route path="/userpanel" component={UserPanel} />
          <Route path="/userposts/:id" component={UserPosts} />
          <Route path="/editpost" component={EditPost} />
        </Container>
      </Router>
reactjs react-router router
1个回答
0
投票

我相信您错过了中间的<Switch />组件。

尝试以下操作:

<Router>
   <Switch>
        <Header />
        <Container history={props.history}>
          <Route exact path="/" component={SelectLogin} />
          { /* all the other routes */ }
          <Route path="/editpost" component={EditPost} />
        </Container>
   </Switch>
</Router>

请参见基本路由选择示例here

我希望这会有所帮助!

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