Ionic-framework: Multiple values of NavParams does not work with dynamic links

Created on 26 Apr 2017  路  9Comments  路  Source: ionic-team/ionic-framework

Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

If i use dynamic link in deep link support,

@IonicPage({
  name: 'detail-page',
  segment: 'detail/:id'
})

when i put 2 values id and name in param value

 pushPage(detailInfo) {
    // Push an `id` to the `'detail-page'`
    this.navCtrl.push('detail-page', {
      'id': detailInfo.id,
      'name': 'Example'
    })
  }

then i can only get id value, but value of name is undefined

export class MyPage{
 constructor(public params: NavParams){
   this.params.get('id');
   this.params.get('name'); // name is undefined
 }
}

Expected behavior:

It should return value for name attribute.

export class MyPage{
 constructor(public params: NavParams){
   this.params.get('id');
   this.params.get('name'); // name is should be `Example`
 }
}

Steps to reproduce:

Related code:

insert any relevant code here

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

insert the output from ionic info here

Most helpful comment

If the name param is in segment like 'detail/:id/:name', then url '/#/detail/12' won't work to get the right detail page.

How can 'name' be an optional param? Like @patrickmcd mentioned? @jgw96

All 9 comments

Hello, thanks for opening an issue with us. If you change to this @IonicPage({ name: 'detail-page', segment: 'detail/:id/:name' }) does this work?

You shouldn't need to put everything in the segment. The id could be the only thing required for building the page when navigated to by URL, while the other stuff could be optional, nice-to-have data.

this.navCtrl.push('detail-page', {

  // required
  id: detailInfo.id,

  // other params are optional
  all: 'kinds',
  of: 'random',
  params: 'for',
  who: 'knows',
  what: 'reason'

})

@jgw96 : Sorry for late reply. If i use IonicPage({ name: 'detail-page', segment: 'detail/:id/:name' }) then i can able to get name value from navParams.

No problem! I will be closing this issue for now.

@jgw96: So if name param is not defined in segment, we cannot pass name param to to navController.push?

If the name param is in segment like 'detail/:id/:name', then url '/#/detail/12' won't work to get the right detail page.

How can 'name' be an optional param? Like @patrickmcd mentioned? @jgw96

Hello

is there any way to refresh current page (Ctrl +F5 or copy url and open url in new tab) with all params in ionic 3 ?

+1 I am facing the same issue as well. I am building an Ionic app with WordPress as my backed. When I click on the post, I need the URL to be like mydomain.com/post/name but the post can be retrieved based on post id. even though i have post id sent through the navParams, i cannot access it on page refresh unless i pass it in the URL like so mydomain.com/post/id/name.

Did anyone find a solution to this?

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings