0

I am using react-navigation v6 and expo 49. Bundler for web is webpack.

I need help with react navigation. It is around how links are generated. I have created a linking config which has a config like

[screenNames.itemDetail]: {
  path: "item-detail/:itemId",
  exact: true,
}

I am using useLinkProps to generate href links on web. Here is that code snippet

const { onPress: onLinkPress, ...linkProps } = useLinkProps({
  to: {
    screen: screenNames.itemDetail,
    params: {
      itemId: item.id,
      origin: "search",
    },
  },
});

If I am on same browser tab and click on the link that gets generated. I go to correct link which is /item-detail/40?origin=search. However, if I use ⌘+click or right click to open in new tab, the link that I get is /item-detail?itemId=40&origin=search. Notice that itemId is a param now.

How do I make sure that link that is generated is always item-detail/40?

Here is a snack link that reproduces this issue https://snack.expo.dev/@khageshfoodapp/hello-react-navigation-|-react-navigation

I don't want to create the exact link string myself. I know I can always serialize params for query string myself and give react navigation the exact path. By doing this, I loose strict type checking for params and screen names.

1 Answer 1

0

I realized that I needed to pass exact same structure to useLinkProps as we have in our navigator. So, if I do below then everything is fine.

useLinkProps({
  to: {
    screen: "main-drawer",
    params: {
      screen: screenNames.itemDetail,
      params: {
        itemId: item.id,
        origin: "search",
      },
    },
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.