Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it best practice to use router.navigate in Components or Services? [closed]

I don't know the philosophies underlying angular, especially regarding testing, well enough to know if I should prefer to use router.navigate() in Components or Services.

For example, suppose you have a LogInComponent that manages your log in form and an AuthService that handles talking to the server. When a user successfully logs in, you want to redirect them from the log in screen to the home page of the application. Is it best to do that in LogInComponent or AuthService?

like image 215
Philip Avatar asked Oct 24 '25 09:10

Philip


1 Answers

Definitely Component, the Services are only supposed to bring the data you want, it should not know anything about the Presentation, whether its a Single Page Application, a simple static pages, a hybrid or native app, let alone how you navigate between them, that way you can change this later and you can reuse your whole services package.

like image 140
Langley Avatar answered Oct 25 '25 23:10

Langley