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?

2
  • Your forEach keeps overwriting. I’d expect only the last dynamicRoute to actually work. this.router.resetConfig([…dynamicRoutes, ...this.router.config]); Commented Sep 4, 2021 at 17:05
  • Yes. But event in that case last route should work but it didn't. Commented Sep 6, 2021 at 8:33

1 Answer 1

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'
    }

]
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Yes , if i use redirectTO it will change the url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.