Ionic2 Optional Anchor Segment Parameters

I cannot find any document explaining how to use optional parameters in segments.

In my app.module.ts, I have this deepLinkConfig:

let deepLinkConfig = {
  links: [{
    component: HomePage, name: 'Home', segment: 'home'
  }, {
    component: ConnexionPage, name: 'Connexion', segment: 'connexion'
  }, {
    component: InscriptionPage, name: 'Inscription', segment: 'inscription'
  }, {
    component: ProfilePage, name: 'Profile', segment: 'profile/:userId'
  }, {
    component: ExplorePage, name: 'Explore', segment: 'explore'
  }, {
    component: FAQPage, name: 'FAQ', segment: 'faq'
  }]
};

...
imports: [
    ...
    IonicModule.forRoot(MyApp, {}, deepLinkConfig);
],

      

The user must be able to access their profile with /profile

, but also access another user profile with /profile/:userId

. But when I try to access / profile, I get an error:

Unprepared (in promise): Invalid views to insert

Through navCtrl you can go to the "profile" with an empty string as userId, but after you activate the page, it will be empty.

Is there a way to make parameters optional in deeplinking?

+3


source to share





All Articles