React router 围绕Auth0示例需求向路由器添加历史记录
遵循时,代码指示以下内容:React router 围绕Auth0示例需求向路由器添加历史记录,react-router,auth0,React Router,Auth0,遵循时,代码指示以下内容: function App() { return ( <div className="App"> {/* Don't forget to include the history module */} <Router history={history}> <header> <NavBar /> </header>
function App() {
return (
<div className="App">
{/* Don't forget to include the history module */}
<Router history={history}>
<header>
<NavBar />
</header>
<Switch>
<Route path="/" exact />
<Route path="/profile" component={Profile} />
</Switch>
</Router>
</div>
);
}
函数应用程序(){
返回(
{/*别忘了包括历史模块*/}
);
}
然而,当试图提供
历史记录以响应路由器时,它会返回一个错误!那么为什么Auth0需要这样做,有没有办法解决呢?您能解释一下返回的错误吗?我不认为这是一个硬依赖,但作为一个最佳实践。React导航与常规浏览器导航不同。历史记录包提供了浏览器历史记录和位置API的实现,从而改进了react路由。在auth0示例中,history.js只返回createBrowserHistory实例,该实例将与react router一起使用。我发现这篇文章对于理解历史API非常有用。