angularionic3deep-linking

How to prevent Ionic from navigating to the first page every time I refresh the page


I am using Ionic 3 + Angular and working on Deeplinks. I have configured following routes:

IonicModule.forRoot(
      App,
      { locationStrategy: 'hash'  },
      {
        links: [
          {
            component: ReportPage,
            segment: "report/:locationId/:itemId"
          },
          {
            component: HomePage,
            segment: "home/:locationId/:itemId"
          },
       ]
     }
 )

If I hit home/1/2 it redirects me to home page as expected. If I hit report/1/2 it redirects me to report page as expected.

But problem comes when I hit home/1/2 and control refresh the page it navigates me to the report page.

I tried to use the ionicPage segment but no luck.

Thanks in advance.


Solution

  • It will work if you can set name in link object Like :

    links: [
    
            {
              component: HomePage,
              segment: "home/:locationId/:itemId",
              name: 'home',
            },
             {
              component: ReportPage,
              name: 'report',
              segment: "report/:locationId/:itemId"
            },
         ]