Custom Routes in react admin

纵饮孤独 提交于 2019-12-10 11:17:00

问题


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 has and Edit component with SimpleForm

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


回答1:


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} />];

Then import the file in your App.js

import customRoutes from './routes';


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


来源:https://stackoverflow.com/questions/51525116/custom-routes-in-react-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!