index.ts 389 B

12345678910111213141516171819202122
  1. import { router, useStore } from "@/cool";
  2. const ignoreToken = [
  3. "/pages/index/home",
  4. "/pages/index/my",
  5. "/pages/user/login",
  6. "/pages/user/doc"
  7. ];
  8. router.beforeEach((to, next) => {
  9. const { user } = useStore();
  10. if (ignoreToken.includes(to.path) || to.path.startsWith("/pages/demo")) {
  11. next();
  12. } else {
  13. if (!user.isNull()) {
  14. next();
  15. } else {
  16. router.login();
  17. }
  18. }
  19. });