I am developing a FunctionalComponent
that will render a list of items, in Ionic
with React
. The component will be reused for every type of item's status. I am passing the item's status as a url-param
.
I want to get the url-param
and display it as the List Title and use it to call the API for the matched items. Rendering the List-Component
the url param's match
renders as undefined.
How can I get the url param in the Component?
Link to the List-Page
at Dashboard.tsx:
<IonCard className="card-body" href="/list/onschedule">
App.tsx:
<IonRouterOutlet>
<Route exact path="/login" component={Login} />
<Route exact path="/" render={() => <Redirect to="/dashboard" />} />
<PrivateRoute path="/dashboard" component={Dashboard} exact={true} />
<PrivateRoute path="/list/:status" component={List} />
</IonRouterOutlet>
In the PrivateRoute
component I placed a console.log
for the props and it's getting the param:
List.tsx:
interface StatusMatchProps extends RouteComponentProps<{
status: string;
}> {}
const List: React.FunctionComponent<StatusMatchProps> = ({match}) => {
console.log("match: " + match)
return (
<>
<IonTitle>{match.params.status}</IonTitle>
);
};
Chrome's console output: