2

I have a page called http://example.com/consultation which represents the landing page (first page) of angular in my site, and the routes are as shown below. The Question is: when the link is http://example.com/consultation (without anything after consultation i need to distribute routing randomly to ask-question and service-page. Any idea how to achieve this?

export const routes: Routes = [
    {
        path: 'consultation',
        component: OnlineConsulationComponent,
        children: [
            { path: '', redirectTo: 'ask-question', pathMatch: 'full' },
            { path: 'ask-question', component: AskQuestion },
            { path: 'service-page', component: ServicePage },
            { path: '**', redirectTo: 'ask-question' }
        ]
    }
];

2 Answers 2

0

Your redirects should have a slash in front

redirectTo: '/ask-question'

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

1 Comment

Thanks @David, but does this make the random routing to two links?
0

I would do it from the OnlineConsultationComponent ngOnInit function. Just check the route there and if you don't detect 'ask-questions' or 'service-page' inside the active route, then reroute to one of those two chosen randomly. There is no way of doing this through the router directly.

You can also achieve this same behavior with a guard if you don't want to dont want to do it inside the component.

1 Comment

Lol, i just saw this is a two year old question. Hope this helps someone anyways.

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.