【问题标题】:How to create an unauthenticated route in React-admin如何在 React-admin 中创建未经身份验证的路由
【发布时间】:2023-01-11 03:39:42
【问题描述】:

我正在寻找在 React-Admin 上创建未经身份验证的路由。我将我的路线放在管理组件之外,但它不起作用,它总是在 authProvider 中调用我的 checkAuth 函数,我不知道如何仅针对这条路线禁用它。 我的代码如下

<>
    <CustomRoutes>
      <Route path="/products/:slug" element={<AddRecipients/>} />
    </CustomRoutes>
    <Admin dataProvider={DataProvider} authProvider={authProvider}>
      <Resource name="users" list={UsersList} show={UsersShow} edit={UsersEdit} create={UsersCreate} icon={PeopleIcon} />
      <Resource name="candidatures" list={CandidaturesList} show={CandidaturesShow} edit={CandidaturesEdit} create={CandidaturesCreate} icon={NoteAltIcon} />
      <Resource name="recipients" list={RecipientsList} show={RecipientsShow} edit={RecipientsEdit} create={RecipientsCreate} icon={QuestionAnswerIcon} />
      <Resource name="jobs" list={JobsList} show={JobsShow} edit={JobsEdit} create={JobsCreate} icon={WorkIcon} />
      <Resource name="companies" list={CompaniesList} show={CompaniesShow} edit={CompaniesEdit} create={CompaniesCreate} icon={ApartmentIcon} />
    </Admin>
    </>

customRoutes 总是调用 checkAuth 所以它在登录页面上重定向我 我想到达的路线是 /products/:slug

【问题讨论】:

    标签: reactjs typescript react-admin


    【解决方案1】:

    您可以使用 disableAuthentication 属性删除核心视图元素的身份验证,例如 &lt;List&gt;&lt;Create&gt;&lt;Edit&gt;

    希望能帮助到你!

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多