expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps

Home Page:https://docs.expo.dev/routing/introduction/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to nested dynamic route under shared

senghuotlay opened this issue · comments

Which package manager are you using? (Yarn is recommended)

yarn

Summary

i am unable to navigate to products screen at all router.push(`${segment}/products/hello`);

I kept getting this error

index.tsx:49 The action 'NAVIGATE' with payload {"name":"[title]","params":{"title":"hello"}} was not handled by any navigator.

Do you have a screen named '[title]'?

If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.

my sitemap is showing it correctly
image

It seems like the only i can approach that for now is to useQueryParams router.push(${segment}/products?title=hello)

Minimal reproducible example

image

Inside my dynamic layout

import { BackButton } from '@klotti/ui';
import { Stack, useRouter } from 'expo-router';

type Group<T extends string> = `(${T})`;
export type SharedSegment = Group<'index'> | Group<'search'>;

export default function DynamicLayout({ segment }: { segment: SharedSegment }) {
  const { back } = useRouter();
  if (segment === '(index)') {
    return (
      <Stack
        screenOptions={{
          headerLeft: () => <BackButton onPress={back} />
        }}>
        <Stack.Screen
          name='index'
          options={{
            headerShown: false
          }}
        />
        <Stack.Screen
          name='product/[id]'
          options={{
            headerTitle: ''
          }}
        />
        <Stack.Screen
          name='products/[title]'
          options={{
            headerTitle: 'Trending'
          }}
        />
      </Stack>
    );
  }

  return (
    <Stack
      screenOptions={{
        headerLeft: () => <BackButton onPress={back} />
      }}>
      <Stack.Screen
        name='search'
        options={{
          title: 'Search',
          headerLeft: () => null
        }}
      />
      <Stack.Screen
        name='product/[id]'
        options={{
          headerTitle: '',
          headerTransparent: true
        }}
      />
      <Stack.Screen
        name='products/[title]'
        options={{
          headerTitle: 'Products'
        }}
      />
    </Stack>
  );
}

I am able to make it work by doing this, but it seems very unconventional
router.push(`${segment}/products?title=trending`);

image

export const unstable_settings = {
  // Ensure that reloading on `/modal` keeps a back button present.
  initialRouteName: '[title]'
};

export const ProductsLayout = () => {
return <Stack
        screenOptions={{
          headerLeft: () => <BackButton onPress={back} />
        }}>
        <Stack.Screen
          name='[title]'
          initialParams={local}
          options={{
            headerTitle: title
          }}
        />
}

Any update on this guys?

Facing the same issue since version 2.0.0

Facing the same issue while using router.push() from 'expo-router'

maybe related to expo/expo#24457
try this if it works: #793 (comment) temporary solution