【发布时间】:2020-04-13 10:55:47
【问题描述】:
添加 react-router-dom 后,我将其推送到 GitHub https://github.com/iamtheasad/user。在项目 url 中,我的主页显示 https://iamtheasad.github.io/user/,之后我单击另一个菜单项,它重定向到另一个页面,但是当我刷新另一个页面时,它显示 404 页面,单击主页,它把我带到了这个链接 https://iamtheasad.github.io/,它是给我看空白页。
我的导航组件链接:https://github.com/iamtheasad/user/tree/master/src/components/TopNavigation
我的路由器组件链接:https://github.com/iamtheasad/user/tree/master/src/router
我正在尝试添加这些:<NavLink exact activeStyle={{color: '#00a8ee'}} className={this.state.navBarItem} to={process.env.PUBLIC_URL + '/'}>Home</NavLink> </Nav.Link>
和
<Route exact path={process.env.PUBLIC_URL + '/'} component={HomePage}/>
<Route exact path="/service" component={ServicePage}/>
<Route exact path="/course" component={CoursesPage}/>
<Route exact path="/portfolio" component={PortfolioPage}/>
<Route exact path="/contact" component={ContactPage}/>
<Route exact path="/about" component={AboutPage}/>
【问题讨论】:
-
尝试从
to组件中的to属性中删除process.env.PUBLIC_URL,据我所知链接是相对的 -
我刚试过。它没有用。
-
你需要展示你的路由文件的完整代码,你正在渲染路由组件。
-
这是我的路由器文件链接
https://github.com/iamtheasad/user/blob/master/src/router/AppRoute.js
标签: javascript reactjs react-router react-router-v4 react-router-dom