How to define optional segment parameter in Ionic

2019-06-24 15:41发布

问题:

How it is possible to define a optional parameter in Ionic 3 PWA?

My current @IonicPage decorator looks like:

@IonicPage({
    segment: "landing/:id"
})

But the id param must be optional. If I do not pass the id, I receive this error:

Uncaught (in promise): invalid views to insert

How to do it?
Thanks in advance!

回答1:

There is no method yet.You need to send empty string when you don’t need it.That is the workaround for this now.

 this.navCtrl.push('landing', {
      'id': ''
    })