K
K
Konstantin2018-10-26 00:24:57
Angular
Konstantin, 2018-10-26 00:24:57

How to design the correct structure of Angular components?

Installed Angular from CLI, with standard structure. When the entry point is a file:
app.module -> app.component The app.component.html
template file has

<router-outlet>
</router-outlet>
and the site skeleton, which should be visible only after authorization.
Which substitutes other callable components depending on the selected route.
The problem is that when I request an authorization page (login page), it is substituted into this private template. What is wrong. The login page should work as a separate page.
How to organize it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
Qairat, 2018-10-26
@Junart1

It can be done differently. One of the ways out: it is
necessary to register in the routing something like this:

const appRoutes: Routes = [
  { path: '', redirectTo: '/login', pathMatch: 'full' },
  { path: 'login', component: LoginComponent },
  { path: 'main', component: MainComponent}

then, in the LoginComponent component, check whether the person has passed authorization,
if he passed, then we redirect to the desired page, like this:
auth() {
   this.service.getToken(this.login, this.password).then(res) {
       if (res) {
         return this.router.navigate(['/main']);
       }
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question