0

I would like to have my Clubs get data straight from its parent. In the example below. other props such as data and setData are both available. but not id which should be given by the path.

<AuthRoute path="/club/:id">
 <Club data={data} setData={setData} />
</AuthRoute>

const AuthRoute = ({ children, ...props }) => {
  const { isAuthenticated } = useAuth();
  return (
    <Route {...props}>
      {isAuthenticated ? children : <Redirect to="/login" />}
    </Route>
  );
};

export const Club = (props) => {
  console.log(props);
  return <div>Hello World</div>;
};
  • Does this answer your question? [React - How to get parameter value from query string](https://stackoverflow.com/questions/35352638/react-how-to-get-parameter-value-from-query-string) – Felix Haeberle Apr 20 '20 at 09:26
  • No, sadly I would have to change structure and if i did i would not be able to send the other data at the same time. – Adriel Noach Premer Apr 20 '20 at 10:01

2 Answers2

1

I used useParems function in Club that worked.

const { id } = useParams();
0

You should be able to get the id in Club component by

export const Club = (props) => {
  let club_id = props.match.params.id;
  console.log('ClubId is::',club_id);
  return <div>Hello World</div>;
};

subhnet
  • 116
  • 7