react admin 中的自定义路由 [英] Custom Routes in react admin

查看:63
本文介绍了react admin 中的自定义路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义路线

I have created a custom route

<Route
    path="/course-plan/:plan_id/plan-lesson/:id"
    render={props => {
      return <LessonEditPage 
        {...props} 
        resource={'plan-lesson'} 
        record={{planId: props.match.params.plan_id}} 
     />
    }}
  />,

LessonEditPage 具有和使用 SimpleForm 编辑组件

LessonEditPage has and Edit component with SimpleForm

当我进入这个页面时,我发出一个请求 crudGetOne 并且在本地一切都很好,我在我用来发出请求的参数中有 id 和 id,但是当我在服务器上部署此代码时,当我进入这个页面时 params.id 未定义

When I enter this page, I make a request crudGetOne and locally everything is fine, I have and id in my parameters that I use to make request, but when I deploy this code on server, when I enter this page params.id is undefined

我不知道为什么会出现问题

I have no idea why and what can be the problem

推荐答案

你应该创建一个 routes.js 文件:

You should create a routes.js file:

import React from 'react';
import { Route } from 'react-router-dom';
import LessonEditPage from './LessonEditPage';

export default [
    <Route exact path="/course-plan/:plan_id/plan-lesson/:id" component={LessonEditPage} />];

然后在你的 App.js 中导入文件

Then import the file in your App.js

import customRoutes from './routes';


<Admin
     dataProvider={dataProvider}
     customRoutes={customRoutes}
/>

这篇关于react admin 中的自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆