1

I have a angular application. After logging in I want to change my routing operations according to the role of the user. I want to use this role on routing, similar like this,

login result as below,

{
"TOKEN":"tokenhere",
"USERINFO":"userinfor here",
"USERROLE":"1 like admin"
}

And I create a PageService class in that,

export class PageService {
    static getNormalUserRoute() {
        return [
            { path: "", component: MainComponent, data: { state: {} }, canActivate: [NeedAuthGuard] },
            { path: "login", component: LoginComponent, data: { state: {} } },
            //..OthersHere
            { path: "**", component: NotfoundComponent, data: { state: {} }, canActivate: [NeedAuthGuard] },
        ];
    }
    static getAdminUserRoute() {
        return [
            { path: "", component: MainComponent, data: { state: {} }, canActivate: [NeedAuthGuard] },
            { path: "login", component: LoginComponent, data: { state: {} } },
            { path: "management", component: ManagementComponent, data: { state: {} }, canActivate: [NeedAuthGuard] },
            //..Others
            { path: "**", component: NotfoundComponent, data: { state: {} }, canActivate: [NeedAuthGuard] },
        ];
    }
}

After then i call this function like this in app-routing.module.ts

const routes: Routes = PageService.getNormalUserRoute();

I want to change here after user logged application.

Is is possible or any alternative solution?

errorau
  • 2,121
  • 1
  • 14
  • 38

0 Answers0