登录后反应管理员应该重定向到主页但它重定向到以前的 url

React admin after login should redirect to home page but it redirects to the previous url

实际上我以超级管理员的身份登录,可以访问特定的资源,即高管,我从这个页面注销,然后使用无法访问高管页面的高管详细信息登录,因此它呈现“未找到”页面但我希望如果高管登录并且无法访问特定的 url 那么它应该重定向到仪表板页面。

您可以使用自定义 saga 来替换此路由:

logoutSaga.js:

import { put, takeEvery } from 'redux-saga/effects'
import { replace } from 'connected-react-router'
import { UNREGISTER_RESOURCE } from 'react-admin'

function* logoutMonitor(action) {
  try {
    if (action.payload === 'name_one_your_resources') {
      yield put(replace({pathname: '/login', state: {nextPathname: '/'}})) // Replacing the route for the next entry!
    }
  } catch (error) {
    console.warn('logoutSaga:', error)
  }
}

function* logoutSaga() {
  yield takeEvery([UNREGISTER_RESOURCE], logoutMonitor) // UNREGISTER_RESOURCE - one of the last Redux Action at logout
}

export default logoutSaga  

连接自定义 Saga:https://marmelab.com/react-admin/Admin.html#customsagas