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

[Layout children]: No route named "search" exists in nested children

devoren opened this issue · comments

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

yarn

Summary

initialRouteName not working as expected. On root layout:

...
<Stack.Screen name="search" options={{ title: 'Search' }} />
...
image

Search layout:

export default function SearchLayout() {
	return (
		<Stack screenOptions={{ headerShown: false }} initialRouteName="index">
			<Stack.Screen name="index" options={{ presentation: 'fullScreenModal' }} />
			<Stack.Screen name="autocomplete" options={{ presentation: 'fullScreenModal' }} />
		</Stack>
	);
}

[Layout children]: No route named "search" exists in nested children: ["(tabs)", "[...unmatched]", "auth", "notifications/[id]", "search/autocomplete", "search/index", "_sitemap"]

I can't route to search, useRouter().push("/search")

Minimal reproducible example

export const unstable_settings = {
	initialRouteName: 'index',
};

export default function SearchLayout() {
	return (
		<Stack screenOptions={{ headerShown: false }} initialRouteName="index">
			<Stack.Screen name="index" options={{ presentation: 'fullScreenModal' }} />
			<Stack.Screen name="autocomplete" options={{ presentation: 'fullScreenModal' }} />
		</Stack>
	);
}

RootLayout:

<Stack
		initialRouteName="(tabs)"
		screenOptions={{
			headerShadowVisible: false,
		}}>
		<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
		<Stack.Screen name="search" options={{ title: 'Поиск' }} />
	</Stack>

In (tabs) i have a custom tabbar button that routes to '/search' but i can't.
Instead of "index" on the search page, if I create another file whose name is not "index" and then if I navigate to it, it works fine.

Per the error message, use search/index as the name.

FYI -- I think all the downvotes on this one is because the docs say otherwise.

https://docs.expo.dev/router/create-pages/

Files named index match the parent directory and do not add a path segment. For example, app/settings/index.js matches /settings in the app.