Obtain url parameters in ionic2 app on browser platform

When deploying my ionic2 app on the browser platform, I’d like to be able to extract URL parameters in the app.ts:

https://myapp.com/index.html?param=abc

And then in app.ts do something like config.get(“param”).

Seems there’s some documentation about this but its either old or incorrect.

Currently there is not URL parameter support as we’re not updating the URL as you navigate in your app.

I don’t need URL support as I navigate. Rather I need only to obtain URL
parameters at the very start of the application, once off.

Here’s my approach

// Obtain all args (key=val) format and store to array keyvalpair = window.location.search.slice(1).split('&') // Loop through items var x = 0; for (x = 0; x <= keyvalpair.length; x++) { // Split the key from the value var splitted=keyvalpair[x].split('='); var key=splitted[0]; var value=splitted[0]; }

4 Likes

Thanks for that. And just to add, since this code should only run in the browser app, I can use Device.device.platform to determine such thing.