I am new to ionic 2. After a searching everywhere I can not find a direct answer given the following scenario:
- I am building a PWA with ionic 2 (because I will later develop hybrid versions of this app)
- the address where users will find and access my app will be a standard domain like
https://welcometotheapp.com?viewid=0101018737abcdefg
- I am using ionic 2, recently installed on windows 10
- I have started a new blank app project
- My question is NOT related to navigation.
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
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.
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!
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
you can do asplit
like soNote that if there is no
viewId=
then the variable will be undefined. Here are the docs for location.searchI had to use
Location
from@angular/common
. So I believe is worth post another answer: