访问pwa地址的url参数 [英] Access url parameters of pwa address

查看:128
本文介绍了访问pwa地址的url参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是离子2的新手。在搜索到处后找不到直接答案给出以下情况:

I am new to ionic 2. After a searching everywhere I can not find a direct answer given the following scenario:


  1. 我是使用离子2构建PWA(因为我稍后会开发此应用程序的混合版本)

  2. 用户将找到并访问我的应用程序的地址将是一个标准域,如 https://welcometotheapp.com?viewid=0101018737abcdefg

  3. 我正在使用离子2,最近安装在Windows 10上

  4. 我已经开始了一个新的空白应用程序项目

  5. 我的问题与导航无关。

  1. I am building a PWA with ionic 2 (because I will later develop hybrid versions of this app)
  2. the address where users will find and access my app will be a standard domain like https://welcometotheapp.com?viewid=0101018737abcdefg
  3. I am using ionic 2, recently installed on windows 10
  4. I have started a new blank app project
  5. My question is NOT related to navigation.

我的问题是如何访问url参数 viewid ?我需要这个参数,以便应用程序将它发送到我的服务器端REST api并获取正确的json数据。我的用户通过SMS接收带有参数的URL作为链接。
我试图利用这个问题

My question is how do I go about accessing the url parameter viewid? I need this parameter so that the app send it to my server side REST api and get the right json data. My users receive the url with the parameter as a link by SMS. I have tried to make use of several suggestions like this question

但我正在转动轮子。我也看过很多来自Josh Morony和其他人的youtube vids,但是没有任何直接关系。

But I'm spinning my wheels. I've also watched quite a number of youtube vids from Josh Morony and others but again nothing directly related.

有人可以帮忙解决这个问题吗?作为一个新手,如果使用ionic2空白模板结构在代码中使用什么代码进行注释,那将非常有用。谢谢偷看!

Can someone help with this question? As a newbie, it would be very helpful if code snips were annotated with what code goes in what file given the ionic2 blank template structure. Thanks peeps!

推荐答案

你可以试试普通的旧javascript。我不认为这是离子特有的。因为它不是主要基于导航,所以 NavParams 将无效,我猜。

You could try plain old javascript. I dont think this is anything specific to ionic. And because it is not primarily navigation based then the NavParams would not work, i am guessing.

In .js 你可以这样做拆分

In .js you can do a split like so

let myParam = location.search.split('viewid=')[1];

请注意,如果没有 viewId = 那么变量将是未定义的。以下是 location.search 的文档

Note that if there is no viewId= then the variable will be undefined. Here are the docs for location.search

这篇关于访问pwa地址的url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆