[英]How to re-route a React-Admin url
I'm trying to configure the login page for my React-Admin app.我正在尝试为我的 React-Admin 应用程序配置登录页面。 I'm using
authProvider
and LoginPage
components, as per the documentation and my login process is generally working.根据文档,我正在使用
authProvider
和LoginPage
组件,并且我的登录过程通常正常工作。
I have the app running locally on port 3000. But when I go to http://localhost:3000, I'm automatically redirected to http://localhost:3000/#/login.我的应用程序在端口 3000 上本地运行。但是当我从 go 到 http://localhost:3000 时,我会自动重定向到 Z80791B3AE7002CB88C246876D9FAA8FZ://3000/#8FZ8。
What specifically is driving that redirection?具体是什么推动了这种重定向? I don't specify that.../#/login url within the app itself.
我没有在应用程序本身中指定.../#/login url。
I'm using an old version of React-Admin (2.9), which I understand uses Redux.我使用的是旧版本的 React-Admin (2.9),据我所知使用的是 Redux。 Is that redirection to.../#/login a function of Redux?
重定向到.../#/login 是 Redux 的 function 吗? Or of React-Admin itself?
还是 React-Admin 本身?
My understanding is I can maybe use HashHistory or BrowserHistory to prevent the # - but not sure if that's compatible with React-Admin.我的理解是我可以使用 HashHistory 或 BrowserHistory 来防止 # - 但不确定这是否与 React-Admin 兼容。
The actual issue I'm having is that once I deploy the app to my domain, the login process behaves differently compared to when I run on localhost - which is making pre-deployment testing difficult.我遇到的实际问题是,一旦我将应用程序部署到我的域,登录过程的行为与我在 localhost 上运行时的行为不同——这使得部署前测试变得困难。
That is, http://localhost:3000 and http://localhost:3000/#/login both allow me to login successfully.即 http://localhost:3000 和 http://localhost:3000/#/login 都让我登录成功。 But when I deploy to my domain, http://www.example.com allows me to login, while http://www.example.com/#/login does not.
但是当我部署到我的域时, http://www.example.com允许我登录,而http://www.example.com/#/login不允许。
Any idea why this would be?知道为什么会这样吗? And can I configure a React-Admin app to not re-route to http://www.example.com/#/login ?
我可以将 React-Admin 应用程序配置为不重新路由到http://www.example.com/#/login吗?
https://marmelab.com/react-admin/AuthProviderWriting.html https://marmelab.com/react-admin/AuthProviderWriting.html
"If the promise is rejected, react-admin redirects by default to the /login page. You can override where to redirect the user in checkAuth(), by rejecting an object with a redirectTo property:" “如果 promise 被拒绝,react-admin 默认重定向到 /login 页面。您可以通过使用 redirectTo 属性拒绝 object 来覆盖在 checkAuth() 中重定向用户的位置:”
// in src/authProvider.js
export default {
login: ({ username, password }) => { /* ... */ },
checkError: (error) => { /* ... */ },
checkAuth: () => localStorage.getItem('auth')
? Promise.resolve()
: Promise.reject({ redirectTo: '/no-access' }),
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.