Reputation: 1800
I am very new to Angular (4) and I would like to know if it is possible to call a method based on a specific url, similar to Ruby on Rails where routes are dispatch to controller actions.
For example, if I have the route http://example.com/#/home/success I would like to call the home component's success method.
Upvotes: 0
Views: 1574
Reputation: 799
If you mean statically, see: https://angular.io/docs/ts/latest/guide/router.html
Code sample:
const appRoutes: Routes = [
{ path: 'home/:message', component: HomeComponent },
{ path: 'hero/:id', component: HeroDetailComponent },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
]
})
export class AppModule { }`
You can use ActivatedRoute
to get the params.
Upvotes: 2