Closed kishansiliconinfo closed 6 years ago
You can customize redirection with function and write your custom logic there
permissions: {
only: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
if (route.params['id'] === 42) {
return ['MANAGER', "UTILS"]
} else {
return 'ADMIN'
}
}
I know this redirection method but wanted to stay on current page after page refresh.
Do you load permissions on page refresh? https://github.com/AlexKhymenko/ngx-permissions/wiki/common-use-cases#save-permissions-on-page-refresh
After user is logged in then i set permission from get token which is work as expected but when user refresh any component after login then it's redirect to default route.
You need to save them forexample in local Storage and the load them before application starts. The problem is when you refresh the page all data is lost including permissions and the application need them back. so the best way is to save to localStorage and then load again.
I used localstorage to set the user object and get userobject but i assigned logged user role to ngx permission and then we used in route.
Just need 2 answers.
No i don't have this permission on starting on the app. assigning permission after user login
So the problem is. When user logins you assign permissions everything is good. But then you refresh and the whole data is lost including permissions. The user triest to access the page. Router checkes the permissions for him to view the page. There are no permissions there. User redirects to another page.
So You need to save permissions on login to localStorate. And before app starts load them to ngxPermissionsService again. https://www.intertech.com/Blog/angular-4-tutorial-run-code-during-app-initialization/
Current behavior
We have 3 child route and 1 root route
I used to build angular 4 application with nodejs we have 2 admin panel, 1 site and app.module.ts we used for lazy loading, ngx-permissions, NgxPermissionsGuard.
After the user login from oneadmin they can access every route but if user is in dashboard user can't able to refresh page, if user refresh page it's redirect to http://127.0.0.1:3000.
http://127.0.0.1:3000/oneadmin/dashboard http://127.0.0.1:3000/oneadmin/profile
here is route code
Expected behavior
if user refresh the page it want redirect to to anywhere just stay them in to current page. http://127.0.0.1:3000/oneadmin/dashboard
Environment