question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: `match.params` is always an empty object when using `Redirect` in `IonRouterOutlet`

See original GitHub issue

Prequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

When rendering a Redirect component in IonRouterOutlet, when navigating to other pages that utilise parameters in the URL (for example, /tab1/:id), the match.params object will always be empty. This means that parameters cannot be extracted using useParams or reading the props.match.params object directly.

Expected Behavior

After a Redirect component is rendered and it takes the user to the desired page, I would expect any subsequent page visits to be populated with parameters if they are in the URL.

Steps to Reproduce

To reproduce using the code reproduction repo listed:

  1. Navigate to localhost:8100 (or the test app) in a new tab. This should load tab 2.
  2. Click on “Tab 1”. This should take you to /tab1/TESTING.
  3. The page should read “Tab 1 with param: undefined” when it should actually say “Tab 1 with param: TESTING”.

Code Reproduction URL

https://github.com/Nevvulo/ionic-router-redirect-issue

Ionic Info

Ionic:

Ionic CLI : 6.16.3 (/Users/bswar/.nvm/versions/node/v14.16.0/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/react 5.6.13

Utility:

cordova-res : not installed globally native-run : not installed globally

System:

NodeJS : v14.16.0 (/Users/bswar/.nvm/versions/node/v14.16.0/bin/node) npm : 6.14.11 OS : macOS Big Sur

Additional Information

Related issues: https://github.com/ionic-team/ionic-framework/issues/22230

It’s worth mentioning that the official documentation for v5 states that this is valid for a fallback route: https://ionicframework.com/docs/react/navigation#fallback-route

Here is the diff containing just the changes that introduce the problem: https://github.com/Nevvulo/ionic-router-redirect-issue/commit/dfb52bacad714864a8faf1ae435d456eb0a5b956

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:14

github_iconTop GitHub Comments

1reaction
wmaddencommented, Mar 14, 2022

@thomasklemm using <Switch> instead of <IonRouterOutlet> means there will be no transitions between pages.

It’s shocking the Ionic team hasn’t even responded to this bug in the router since it was raised in 2018.

Bump

1reaction
thomasklemmcommented, Jan 21, 2022

Created a minimal reproduction of this bug including a screen recording, where the match.params are empty if a redirect via a fallback route has happened at the beginning of the session.

Wrapping the routes in a <Switch> component from react-router inside of <IonRouterOutlet> fixed the situation for me, the fallback route is now working, params get parsed properly (Found this solution via this message in Discord)

Read more comments on GitHub >

github_iconTop Results From Across the Web

getting empty value from this.props.match.params while it is ...
Hi I am trying to access my params from my react router but it always shows me an empty object. this is my...
Read more >
Error with Params on first load of page on Real Device
Now I'm having a issue with params in URLs, I'll explain better possible. ... useParams or with RouteComponentProps (match.params.groupid).
Read more >
Understanding Angular Routing in Ionic Apps - Devdactic
The good thing (sometimes, not always) is that when you use the Ionic ... an empty path (”) and the first item that...
Read more >
Working with Angular 14 Router - Techiediaries
We'll learn how to use multiple outlets, redirect users from the empty path, use wild-card paths to implement 404 error pages and lazy...
Read more >
Building a full mobile app with TypeScript, Ionic, React, and ...
Now, let's break down the code and see what we are doing. IonRouterOutlet component. <IonRouterOutlet> <Route ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found