AlexKhymenko / ngx-permissions

Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
MIT License
936 stars 126 forks source link

Guard is not working with angular SSR #200

Closed RezDev94 closed 1 year ago

RezDev94 commented 2 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[*] Bug report  
[ ] Feature request
[ ] Documentation issue or request

Current behavior

Guard not working in angular ssr. When I hit refresh on browser, the home page loads at first, then immediately switches to expected route that has the canActivate option.

Expected behavior

The home page should not load at all when I hit refresh.

Minimal reproduction of the problem with instructions

const routes: Routes = [
    {
        path: '',
        component: MainComponent,
        children: [
            {
                path: 'panel',
                data: {
                    permissions: {
                        redirectTo: '/'
                    }
                },
                canActivate: [NgxPermissionsGuard],
                loadChildren: () => import('./panel/panel.module').then(m => m.PanelModule),
            },
            {
                path: '',
                loadChildren: () => import('./home-page/home-page.module').then(m => m.HomePageModule)
            }
        ]
    }
];

Environment


Angular version: 12.2.0
ngx-permissions version: 13.0.1

Browser:
- [*] Edge version 102.0.1245.44 (Official build) (64-bit)