【发布时间】:2019-07-31 13:03:13
【问题描述】:
我按照教程在一个简单的 create-react-app 上设置 Auth0。到目前为止,我在项目中唯一拥有的是身份验证和路由。在 localhost 中开发时,应用运行良好:
- /路由到
/home,并显示当前登录状态 - /home 路由到
/home,^ - /callback,由身份验证服务调用,路由正常,处理身份验证并重定向到登录页面。
正如我所提到的,所有这些路由都在开发中运行良好。我能够看到一个登录页面,按登录,使用凭据登录,通过/callback 重新路由回到主页,并且只有在您登录时才能看到材料。然后我能够注销并再次正确路由返回登录页面。
我将应用程序部署到了一个网站 (https://dashboard.xxxxx.com),但除了 / 之外,其他路由都不起作用。所以https://dashboard.xxxxx.com 有效,但找不到https://dashboard.xxxxx.com/home 和https://dashboard.xxxxx.com/callback。
这会导致 auth0 服务无法登录,因为它重定向到 https://dashboard.xxxxx.com/callback 但该页面不存在。
我从react-router-dom 开始只使用Routes 的Router,然后我尝试使用带有Switch 和Routes 的Router。然后我尝试了BrowserRouter,然后尝试了HashRouter,但都没有奏效。我当前的代码如下:
<HashRouter history={history} component={Home}>
<Switch>
<Route exact path='/' render={(props) => <Home auth={auth} {...props}/>}/>
<Route exact path='/home' render={(props) => <Home auth={auth} {...props}/>}/>
<Route exact path='/callback' render={(props) => {
handleAuth(props);
return <Callback {...props}/>
}}/>
</Switch>
</HashRouter>
【问题讨论】:
标签: javascript reactjs authentication auth0 react-router-dom