【发布时间】:2026-01-24 06:50:01
【问题描述】:
我正在使用带有 Firebase 集成的 React Native v0.63+ 和 React Navigation 5。我必须解决两个问题,这些问题涉及到应用程序的某些部分的深度链接,为了呈现视图,需要一些 props.route.params 包含的对象,例如 profile,这些对象可能会或可能不会保存敏感数据以放入纯文本中网址。
为了导航到某个配置文件而不将整个配置文件字符串化为无休止的 url,我认为我可以将 id 解析为必须从 api 获取的 profile 以便由看法。但是我误解了react-navigation parse 的功能。
但是,我很难找出正确的方法。我该怎么做?
这是我的linking 对象:
export const linking = {
prefixes: ['myapp://'],
config: {
Login: 'login',
Signup: 'signup',
PersonalInfo: 'personalinfo',
Drawer: {
path: "app",
screens: {
Saved: "saved",
Details: "details",
Trend: "trend",
Profile: {
path: "profile/:id?",
parse: {
id: Number, // <-- this is my profile id param
},
},
EditProfile: "editprofile",
Multimedia: "multimedia",
Premium: "premium",
Chat: "chat",
LikeView: "likes",
ReseedView: "reseeds",
Tabs: {
path: "tabs",
exact: true,
screens: {
Main: "main",
Escribir: "escribir",
Notificaciones: "notificaciones",
Mensajes: "mensajes"
}
},
},
},
},
这就是应用程序已经处理传入的profile 以呈现它的方式:
//from any component within navigation reach
navigation.push('Profile',{profile, isMine});
//Profile component
const ProfileScreen = (props) => {
const { profile, isMine } = props.route.params;
const [profileOwner, setProfile] = useState(profile);
//...
【问题讨论】:
标签: react-native async-await deep-linking react-navigation-v5