R H
R H

Reputation: 1227

How to provide props to custom route in react-admin?

I'm using reac-admin, and want that after edit to redirect the user to custom route.

  <Edit {...props}>
        <TabbedForm redirect={redirect(`/XXX/${props.id}/YYY`)}  >

       {/* fileds */}

        </TabbedForm >
  </Edit>

in the custom routes I have this route:

    <Route exact path="/XXX/:id/YYY" render={(props) => <MyRoute {...props} />} />

My problem is how to pass props like in show?

why when redirect to show : redirect="show", the props which are passed are different than when redirect to a custom route?

There are missed props which I need them like the id.

What sholud I do to solve my problem?

Thank you!

Upvotes: 1

Views: 707

Answers (1)

Gildas Garcia
Gildas Garcia

Reputation: 7066

You have two ways to do that:

First option

<Route exact path="/XXX/:id/YYY" render={() => <MyRoute />} />

And inside MyRoute:

import { useParams } from 'react-router';

const MyRoute = () => {
    let { id } = useParams();
    // ...
}

Second option

<Route exact path="/XXX/:id/YYY" render={(props) => <MyRoute id={props.match.params.id} />} />

Upvotes: 6

Related Questions