【发布时间】:2021-02-27 05:04:54
【问题描述】:
我正在尝试为带有 react native 的 web 应用程序配置 react-navigation。为此,我在 NavigationContainer 上设置了链接选项,以便我可以使用以下代码从浏览器 url 访问我的页面:
const linking = {
prefixes: ['http://localhost:8080/', 'http://localhost:8080', 'localhost:8080'],
// prefixes: [prefix],
config: {
screens: {
SignIn: "SignIn",
SignUp: "SignUp",
Landing: '*',
},
}
};
function AppContainer() {
return (
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
<AppStack.Navigator>
<AppStack.Screen name="SignIn" component={SignInPage}/>
<AppStack.Screen name="Landing" component={LandingPage}/>
<AppStack.Screen name="SignUp" component={SignUpPage}/>
<AppStack.Screen name="Home" component={HomePage}/>
</AppStack.Navigator>
</NavigationContainer>
);
}
当我转到“http://localhost:8080/”时,我被重定向到“http://localhost:8080/SignIn”(这很好),并且应用程序正在运行。问题是,如果我从浏览器转到“http://localhost:8080/SignIn”,我会得到“Cannot GET /SignIn”,并且应用程序无法运行......
我正在使用这些版本:
"@react-navigation/bottom-tabs": "^5.11.1",
"@react-navigation/native": "^5.8.9",
"@react-navigation/stack": "^5.12.5",
【问题讨论】:
-
您没有到“localhost:8080/Signin”的直接路由。我会将它添加到前缀数组中
-
将“localhost:8080/Signin”或“localhost:8080/Signin”添加到前缀数组不起作用
标签: react-native react-navigation webpack-dev-server deep-linking react-native-web