Isabelle
Isabelle

Reputation: 1517

Ionic 2 / Angular 2 Routing - Progressive Web App

I'm searching the web to find a solution to implement url routing in Ionic2, I can't seem to find a way to access a page using a URL.

  1. Has it been implemented in Ionic 2?
  2. Should the Angular 2 router be used? Does it work with Ionic 2?

I need to be able to get the physical url of a page within the web app; in order to be able to share it outside the web app.

Thank you,

Upvotes: 3

Views: 4694

Answers (2)

Elie
Elie

Reputation: 544

I think you are looking for the Ionic service DeepLinker. That does not replace the FILO/NavController but provide a way to define and display specific views based on URLs.

In your main module add:

imports: [
  IonicModule.forRoot(MyApp, {}, {
      links: [
         { component: DetailPage, name: 'Detail', segment: 'detail/:userId' }
     ]
  })
]

The full documentation here.

Also, if you also release your PWA on the AppStore/Play Store, you can use the native plugin Ionic Deeplinks.

Upvotes: 7

Gabriel Barreto
Gabriel Barreto

Reputation: 6421

  1. Ionic 2 uses a pile FILO schema for routing with his NavController methods ( like push, pop, setRoot). And you don't need to use a sequence for it like you would do with a Routing system, like to access page 2 i need to go through page 0 and 1, you can just push(NewPage) and it will work, so it gives you a much better control over your application pages and how they interact.

  2. I've never seen anyone talking about using it. If the NavController uses the Angular 2 routing in its background i don't know, will search for this, but the Ionic NavController is easy to use and works very good on most cases, the only case it doesn't support yet is passing parameters back within his pop() method, for this i use a modal and style it totally like a normal page. You can also use setRoot instead of pop to pass data like so.

    this.navCtrl.setRoot(MyPage, this.Data);
    

For more information please see the ionic 2 documentation on navigation

Upvotes: 0

Related Questions