SuperManort
SuperManort

Reputation: 67

Custom Routes in 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 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

Upvotes: 6

Views: 10007

Answers (1)

Othmane
Othmane

Reputation: 289

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

Upvotes: 4

Related Questions