Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用react路由器重新加载页面重定向到主页面_Reactjs_React Router_Router - Fatal编程技术网

Reactjs 使用react路由器重新加载页面重定向到主页面

Reactjs 使用react路由器重新加载页面重定向到主页面,reactjs,react-router,router,Reactjs,React Router,Router,当我尝试重新加载子页面时,应用程序会将我重定向到主页。 当我输入浏览器子页面(例如:/about)时,应用程序会将我重定向到主页。 这是我在App.js中的路由器组件 另外,我在React中使用箭头函数 <Router> <Header /> <Container history={props.history}> <Route exact path="/" component={SelectLogin}

当我尝试重新加载子页面时,应用程序会将我重定向到主页。 当我输入浏览器子页面(例如:
/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>


> 我相信你在中间错过了<代码> <代码>组件。

请尝试以下操作:

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

{/*所有其他路由*/}
请参见基本路由示例


我希望这有帮助

例如,尝试将
exact
添加到具有
path=“/about”
@mattxml的路由中