使用react native expo进行深层链接-不打开屏幕

时间:2020-10-13 16:12:17

标签: react-native expo deep-linking

方案:用户1与用户2共享了注册链接

用户2单击了链接

预期结果:应该会打开“注册”屏幕

实际结果:它没有打开而是打开了默认的第一个导航器

点击链接:url:'exp://kj-97q.anonymous.metordunia.exp.direct:80 /-/ signup'

问题:请提出我在做什么错

export default class App extends React.Component {


componentDidMount (){
 // If the app is NOT already open and the app is opened by clicking an url-->handle an initial url on app opening
  Linking.getInitialURL().then( ( url)=>{
    const {path,queryParams }=Linking.parse(url);
console.log("path url  from if the app is NOT already opened get intiial url:", path);
console.log("path url quary parameter:", queryParams);
console.log(`Linked to app with path: ${path} and data: ${JSON.stringify(queryParams)}`);  
this.props.navigation.navigate(path,queryParams);

  
  });

  // If the app is YES already open and the app is opened by clicking an url-->handle an initial url on app opening
Linking.addEventListener("url",
event=>{

  this.urlRedirect(event.url)
}

)


}



urlRedirect=(url)=>{
  if (! url) return;
  // parse and redirect to new url
  const {path,queryParams }=Linking.parse(url);
  console.log("path url if app is YES already opened add event listener :", path);
console.log("path url quary parameter:", queryParams);
console.log(`Linked to app with path: ${path} and data: ${JSON.stringify(queryParams)}`);
this.props.navigation.navigate(path,queryParams);


}
  1. 导航器详细信息

    const AppNavigator = createBottomTabNavigator({

       Login: {
         screen: Loginstack,
         path:login,
       },
    
       Signup: {
         screen: Signupstack,
         path:'signup',
       },
    

    },

  2. 控制台日志

    从尚未打开应用程序开始的路径URL获取初始URL:注册

    path url quary参数:对象{}

    通过以下路径链接到应用:注册和数据:{}

0 个答案:

没有答案