Phi*_*cks 8 react-native expo expo-router
基于文件的路由并没有完全适合我。早期的 NextJS pages
文件路由很容易工作。由于某种原因,我还没有转换为基于世博路线的文件。可能是因为堆栈、选项卡和插槽的组合。我一直在阅读动态路线文档。当我从选项卡屏幕中导航到 时/pattern/[id]
,由于 Expo 找不到路线,翻译中有些内容丢失了。我尝试了各种各样的方法,但我认为这与我的文件夹结构有关。我想要的是:目的地/pattern/[id]
是(选项卡)的子级,而不是搜索。
app
|__(auth)
|__ _layout.tsx
|__(tabs)
|__ index.tsx
|__ _layout.tsx
|
|__ search
| |__ index.tsx // <-- from where I navigate from
| |__ _layout.tsx
|
|__ pattern // <-- where I want to navigate to
| |__ _layout.tsx
| |__ [id].tsx // <-- dynamic pattern id name
|__ // other tabs content is ok since no navigation
Run Code Online (Sandbox Code Playgroud)
这是我的选项卡的 _layout :
export default function TabLayout() {
return (
<Tabs>
<Tabs.Screen
name="index"
/>
<Tabs.Screen
name="search"
/>
<Tabs.Screen
name="pattern"
options={{
href: null, // based on docs this will hide the tab
/>
</Tabs>
)
};
Run Code Online (Sandbox Code Playgroud)
在我的搜索用户界面上,当我按下要导航到的项目时,
router.push({
pathname: '/pattern', // I have also tried pathname: '/pattern/[id]',
params: {
id: dynamicLabelId
},
});
Run Code Online (Sandbox Code Playgroud)
Expo的错误是找不到路线。路线发生了什么pattern
?:
此后,我使用堆栈添加了不同的 Pattern _layout 而不是插槽:
export default function PatternLayout() {
return (
<Stack>
<Stack.Screen
name="[id]"
</Stack>
);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎无法解决问题...我正在寻求帮助:
router.push({ pathname: '/pattern', params: { id: label },});
工作不正常?[id].tsx
页面?先感谢您我不完全确定,但我想在这里发表两点评论:
如果您想隐藏选项卡,请不要使用href: null
,而是使用tabBarButton: () => null
,这将隐藏选项卡而不会扰乱路由。
您的路由声明router.push({ pathname: '/pattern', params: { id: label },})
会将路由器发送到以下 url: /pattern?id:123
。但你真正想要的是去/pattern/123
。为此,请尝试使用router.push({ pathname: /pattern/`${label}`
.
这对我的动态路由很有用,希望有帮助。
归档时间: |
|
查看次数: |
1479 次 |
最近记录: |