Javascript React Router在使用时显示空白页<;链接>;
在更新了大量依赖项之后,我们现在被迫使用锚定标记,这会导致重定向。在我们使用锚定标记之前,但现在每次我们单击一个链接,它都会转到正确的url ie/屏幕,但只是一个空白页,从不显示组件,下面是我们的父index.tsx文件:Javascript React Router在使用时显示空白页<;链接>;,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,在更新了大量依赖项之后,我们现在被迫使用锚定标记,这会导致重定向。在我们使用锚定标记之前,但现在每次我们单击一个链接,它都会转到正确的url ie/屏幕,但只是一个空白页,从不显示组件,下面是我们的父index.tsx文件: ReactDOM.render( <Provider {...stores}> {/* Changed routes to children */} {/* <Router children={routes} history={crea
ReactDOM.render(
<Provider {...stores}>
{/* Changed routes to children */}
{/* <Router children={routes} history={createHistory} /> */}
<Router history={createHistory}>
<div>
<Switch>
<Route path='/oauth2callback' componentDidMount={console.log()}>
{() => {
if(window.location.href.includes('/oauth2callback'))
{
oauth2callback(window.location.hash)
}
}}
</Route>
<Route path='/testing' component={Get} />
<Route path='/'>
{/* Function that determines if the user is logged in and can allow the authenticated passage or not. If no, it will not render authenticated pages*/}
{() => {
if(auth.loggedIn())
{
console.log("is logged in")
return(
<div>
<Route component={App} history={createHistory}/>
<div className="row" id="wrapper">
<Switch>
{/* <Route path='/screens' component={Screens}/> */}
<Route path='/screens' component={Screens}/>
<Route path='/playlists' component={Playlists}/>
<Route path='/content' component={Content}/>
<Route path='/help' component={HelpNav}/>
<Route component={NotFound}/>
</Switch>
</div>
</div>
)
}
else
{
console.log("is not logged in")
return(
<Route path='/' component={HomeNav}/>
)
}
}}
</Route>
<Route path='401' component={Get} />
</Switch>
</div>
</Router>
</Provider>,
ReactDOM.render(
{/*已更改到子级的路由*/}
{/* */}
{() => {
if(window.location.href.includes('/oauth2callback'))
{
oauth2callback(window.location.hash)
}
}}
{/*函数,确定用户是否已登录,是否允许通过身份验证的通道。如果否,则不会呈现经过身份验证的页面*/}
{() => {
if(auth.loggedIn())
{
console.log(“已登录”)
返回(
{/* */}
)
}
其他的
{
console.log(“未登录”)
返回(
)
}
}}
,
下面是带有导航栏的app.tsx:
<Nav className="mb-nav">
{/* <IndexLinkContainer to="/screens"> */}
<Nav.Item style={{width: widthConstants[0]}}>
<Link to='/screens' style={{color: this.state.navIndex === 0 ? "white" : "bbddba"}}>
Screens
</Link>
</Nav.Item>
{/* </IndexLinkContainer> */}
{/* <LinkContainer to="/playlists"> */}
<Nav.Item style={{width: widthConstants[1]}}>
<a href="/playlists" style={{color: this.state.navIndex === 1 ? "white" : "bbddba"}}>
Playlists
</a>
</Nav.Item>
{/* </LinkContainer> */}
{/* <LinkContainer to="/content"> */}
<Nav.Item style={{width: widthConstants[2]}}>
<a href="/content" style={{color: this.state.navIndex === 2 ? "white" : "bbddba"}}>
Content
</a>
</Nav.Item>
{/* </LinkContainer> */}
{/* <LinkContainer to="/help"> */}
<Nav.Item style={{width: widthConstants[3]}}>
<a href="/help" style={{color: this.state.navIndex === 3 ? "white" : "bbddba"}}>
Help
</a>
</Nav.Item>
{/* </LinkContainer> */}
{this.shouldRenderTouch && <TouchButton/>}
</Nav>
</Navbar.Collapse>
</div>
</Navbar>
{/* */}
屏风
{/* */}
{/* */}
{/* */}
{/* */}
{/* */}
{/* */}
{/* */}
{this.shouldRenderTouch&&}
知道新的react路由器更新中有什么不同之处导致此错误存在吗?阅读react路由器6文章中的“路由和链接与其父级相关”
顺便说一句,奇怪的是,你有
标签而不是链接组件有时修复比我想象的要简单得多,新的更新集成了BrowserRouter而不是路由器,所以我更换了它
<Router history={createHistory}>
与
现在一切都正常运行了出于测试目的,它们最终都会正常运行,因此在单击链接组件后检查url,这是您想要的url还是不想要的url?是的,这是锚定标记下重定向的确切url,就像组件没有渲染一样尝试更改
是的完全一样,只是拒绝显示组件。
<BrowserRouter>