问题
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