0

I have page which renders content based on the params in the url, current route samples are given as follows,

domain.com/page/:pageId (domain.com/page/123456) renders Home Page
domain.com/page/:pageId (domain.com/page/567890) renders Offers Page
domain.com/page/:pageId (domain.com/page/987654) renders Blog Page

Now i want to implement SEO in my site , so my url will be..

domain.com/home renders Home Page
domain.com/offers (domain.com/page/567890) renders Offers Page
domain.com/blog (domain.com/page/987654) renders Blog Page

These pages come dynamically form server.

My Dynamic Route looks like,

 [  {"path": "home",
        "data": {
                "tile": "Landing Page",
                "pageId":"123456" 
        }
    },
    {"path": "offers",
        "data": {
                "tile": "Offers Page",
                "pageId":"567890" 
        }
    },
    {"path": "Bread",
        "data": {
                "tile": "Blog Page",
                "pageId":"987654" 
        }
    }

]

I have pushed my routes as

dynamicRoutes.forEach(route => {
    this.router.resetConfig([route, ...this.router.config]);
});

But the routes are not navigating and gives 404 error.

How do I go about doing this?

Tom
  • 183
  • 1
  • 1
  • 9
  • Your forEach keeps overwriting. I’d expect only the last dynamicRoute to actually work. this.router.resetConfig([…dynamicRoutes, ...this.router.config]); – MikeOne Sep 04 '21 at 17:05
  • Yes. But event in that case last route should work but it didn't. – Tom Sep 06 '21 at 08:33

1 Answers1

1

I think you're looking for the redirectTo feature?

e.g.

[  {"path": "home",
       "data": {
                "tile": "Landing Page",
                "pageId":"123456" 
        },
       "redirectTo: '/page/123456'
    },
    {"path": "offers",
        "data": {
                "tile": "Offers Page",
                "pageId":"567890" 
        },
       "redirectTo: '/page/567890'
    },
    {"path": "Bread",
        "data": {
                "tile": "Blog Page",
                "pageId":"987654" 
        },
       "redirectTo: '/page/987654'
    }

]
Rohith V
  • 1,089
  • 1
  • 9
  • 23
Robert Dempsey
  • 410
  • 2
  • 12
  • Robert, Tom wants to implement SEO on his current dynamic site. So "redirectTo: '/page/123456' code again it will redirect to dynamic page. He wants url should be like this domain.com/home. – Rajesh Kumar Swain Sep 04 '21 at 15:04
  • Yes , if i use redirectTO it will change the url – Tom Sep 05 '21 at 15:26