Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linking config with react-navigation v5.9 for URL with query params

I'm working with react-navigation and I'm trying to configure my linking element because I need it to use it in apps and web to. It works fine with simple URLs but I don't know how exactly include a URL with query params. My URL is /ecare/page?reference=XXX

and here's my linking

const linking = {
    prefixes: ['//my-prefix'],
    config: {
      screens: {
        Invoices: 'ecare/invoices',
        Products: {
          path: 'ecare/page/:reference',
        }
      }
    },
  }

How can I exactly parser my URL from my query param URL to my linking working fine?

like image 519
Elena Martín Castillo Avatar asked Dec 28 '25 12:12

Elena Martín Castillo


1 Answers

A late answer but it might help someone. I've also spent some time on this issue. Here's what I was missing.

Keys in the screens object correspond with the screen name.

So if you have the following screen:

<SomeScreen name={'invoices'} ... />

And you want to navigate to it with the following

const navigationProps = useLinkProps({
    to: {
      screen: 'invoices',
      params: { reference: someValue },
    },
  })

Then you have to specify your screen in the linking config as:

const linking = {
    prefixes: ['//my-prefix'],
    config: {
      screens: {
        ['invoices']: 'invoices/:reference'
      }
    },
  }

Not as Invoices: 'invoices/:reference'

So,

Key == Screen name

Path == any value you want

like image 155
Alex Trofimov Avatar answered Jan 03 '26 10:01

Alex Trofimov