ionic-team / ionic-v3

The repo for Ionic 3.x. For the latest version of Ionic, please see https://github.com/ionic-team/ionic
Other
128 stars 85 forks source link

Keeping url parameters with deeplinking #21

Open ionitron-bot[bot] opened 5 years ago

ionitron-bot[bot] commented 5 years ago

Ionic version: [ ] 1.x [ ] 2.x [x] 3.x

I'm submitting a ... [ ] bug report [x] feature request [ ] support request

Current behavior: Currently when I have a URL with parameters (e.g. ..?a=hello&b=world) they get cut off by Ionic routing.

http://localhost:8100/#/nav/n4/intro?a=hello&b=world gets changed to http://localhost:8100/#/nav/n4/intro.

These parameters are for FB tracking and such and are necessary on all pages.

Expected behavior: http://localhost:8100/#/nav/n4/intro?a=hello&b=world should stay like that.

I would like to keep these parameters. Ideally it would be a settings parameter.

Steps to reproduce: Add ?a=hello&b=world at the end of your URL and do a refresh. The added parameters will be removed.

Related code:

Other information:

Ionic info:

global packages:

    @ionic/cli-utils : 1.5.0
    Cordova CLI      : 6.5.0 
    Ionic CLI        : 3.5.0

local packages:

    @ionic/app-scripts              : 2.0.1
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : android 6.2.3 ios 4.4.0
    Ionic Framework                 : ionic-angular 3.5.0

System:

    Node       : v6.7.0
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b 
    ios-deploy : 1.9.0 
    ios-sim    : 5.0.8 
    npm        : 3.10.3 
Markfu1 commented 5 years ago

所以问题还没有得到有效果的解决方法对吗?

MiataXing commented 5 years ago

所以问题还没有得到有效果的解决方法对吗?

Seems that the answer is a No......

cgbrucezjy commented 5 years ago

is anybody still following up this issue, this is such an essential matter, I have to handle a redirect from 3rd party api where I got no control over the url, so I have to handle query param, upgrade to 4 is not an option for now. any quick solutions?

wf9a5m75 commented 5 years ago

I faced this problem, then I managed on my way. Ionic redirects the first arriving URL to proper URL. You can't retrieve the first arriving URL even if you write in app.components.ts.

That's why you need to write your code in index.html.

Write the below code in your index.html file directly. This keeps the first arriving URL to window.firstURL.

<script type='text/javascript'>
Object.defineProperty(window, "firstURL", {
  enumerable: false,
  value: location.href,
  writable: false
});
</script>

Then you can retrieve it anywhere in your code like this.

const firstURL = (window as any).firstURL;
console.log(firstURL);