|
@@ -14,41 +14,42 @@ router.beforeEach(async (to: Route, _: Route, next: any) => {
|
|
|
NProgress.start();
|
|
|
|
|
|
// Determine whether the user has logged in
|
|
|
- if (UserModule.token) {
|
|
|
- if (to.path === "/login") {
|
|
|
- // If is logged in, redirect to the home page
|
|
|
- next({ path: "/" });
|
|
|
- NProgress.done();
|
|
|
- } else {
|
|
|
- // Check whether the user has obtained his permission roles
|
|
|
- if (UserModule.roles.length === 0) {
|
|
|
- try {
|
|
|
- // Get user info, including roles
|
|
|
- await UserModule.GetUserInfo();
|
|
|
- // Set the replace: true, so the navigation will not leave a history record
|
|
|
- next({ ...to, replace: true });
|
|
|
- } catch (err) {
|
|
|
- // Remove token and redirect to login page
|
|
|
- UserModule.ResetToken();
|
|
|
- Message.error(err || "Has Error");
|
|
|
- next(`/login?redirect=${to.path}`);
|
|
|
- NProgress.done();
|
|
|
- }
|
|
|
- } else {
|
|
|
- next();
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // Has no token
|
|
|
- if (whiteList.indexOf(to.path) !== -1) {
|
|
|
- // In the free login whitelist, go directly
|
|
|
- next();
|
|
|
- } else {
|
|
|
- // Other pages that do not have permission to access are redirected to the login page.
|
|
|
- next(`/login?redirect=${to.path}`);
|
|
|
- NProgress.done();
|
|
|
- }
|
|
|
- }
|
|
|
+// if (UserModule.token) {
|
|
|
+// if (to.path === "/login") {
|
|
|
+// // If is logged in, redirect to the home page
|
|
|
+// next({ path: "/" });
|
|
|
+// NProgress.done();
|
|
|
+// } else {
|
|
|
+// // Check whether the user has obtained his permission roles
|
|
|
+// if (UserModule.roles.length === 0) {
|
|
|
+// try {
|
|
|
+// // Get user info, including roles
|
|
|
+// await UserModule.GetUserInfo();
|
|
|
+// // Set the replace: true, so the navigation will not leave a history record
|
|
|
+// next({ ...to, replace: true });
|
|
|
+// } catch (err) {
|
|
|
+// // Remove token and redirect to login page
|
|
|
+// UserModule.ResetToken();
|
|
|
+// Message.error(err || "Has Error");
|
|
|
+// next(`/login?redirect=${to.path}`);
|
|
|
+// NProgress.done();
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// next();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // Has no token
|
|
|
+// if (whiteList.indexOf(to.path) !== -1) {
|
|
|
+// // In the free login whitelist, go directly
|
|
|
+// next();
|
|
|
+// } else {
|
|
|
+// // Other pages that do not have permission to access are redirected to the login page.
|
|
|
+// next(`/login?redirect=${to.path}`);
|
|
|
+// NProgress.done();
|
|
|
+// }
|
|
|
+// }
|
|
|
+ next();
|
|
|
});
|
|
|
|
|
|
router.afterEach((to: Route) => {
|