Skip to content

Commit

Permalink
fix: router redirect error when logout #98
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Apr 30, 2022
1 parent ba7e405 commit 32c0a15
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 87 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@ant-design/icons-vue": "^6.1.0",
"@vueuse/core": "^8.3.1",
"ant-design-vue": "3.2.2",
"axios": "^0.27.1",
"core-js": "^3.22.2",
"axios": "^0.27.2",
"core-js": "^3.22.3",
"dayjs": "^1.11.1",
"file-saver": "^2.0.5",
"lodash-es": "^4.17.21",
Expand All @@ -53,10 +53,10 @@
"xlsx": "^0.18.5"
},
"devDependencies": {
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@commitlint/cli": "^16.2.4",
"@commitlint/config-conventional": "^16.2.4",
"@types/lodash-es": "^4.17.6",
"@types/node": "^17.0.29",
"@types/node": "^17.0.30",
"@types/webpack-env": "^1.16.4",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
Expand All @@ -70,7 +70,7 @@
"commitizen": "^4.2.4",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"cz-git": "^1.2.3",
"cz-git": "^1.2.8",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "2.26.0",
Expand All @@ -86,15 +86,15 @@
"prettier": "^2.6.2",
"regenerator-runtime": "^0.13.9",
"speed-measure-webpack-plugin": "^1.5.0",
"stylelint": "^14.8.0",
"stylelint": "^14.8.1",
"stylelint-config-html": "^1.0.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"svg-sprite-loader": "^6.0.11",
"typescript": "^4.6.3",
"typescript": "^4.6.4",
"unplugin-vue-define-options": "^0.6.1",
"vue-cli-plugin-windicss": "^1.1.4",
"vue-eslint-parser": "^8.3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/dynamic-table/src/hooks/useTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useTable(props?: Partial<DynamicTableProps>) {
if (Reflect.has(target, key)) {
return unref(target);
}
if (Reflect.has(target.value, key)) {
if (target.value && Reflect.has(target.value, key)) {
return target.value[key];
}
return async (...rest) => {
Expand Down
8 changes: 6 additions & 2 deletions src/layout/header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</template>

<script lang="tsx" setup>
import { computed, type CSSProperties } from 'vue';
import { computed, nextTick, type CSSProperties } from 'vue';
import { useRouter, useRoute, RouteRecordRaw } from 'vue-router';
import {
QuestionCircleOutlined,
Expand All @@ -85,6 +85,7 @@
import { Search, FullScreen, ProjectSetting } from './components/';
import { LocalePicker } from '@/components/basic/locale-picker';
import { useUserStore } from '@/store/modules/user';
import { useKeepAliveStore } from '@/store/modules/keepAlive';
import { useLockscreenStore } from '@/store/modules/lockscreen';
import { LOGIN_NAME } from '@/router/constant';
import { TitleI18n } from '@/components/basic/title-i18n';
Expand All @@ -102,6 +103,7 @@
const userStore = useUserStore();
const themeStore = useThemeStore();
const lockscreenStore = useLockscreenStore();
const keepAliveStore = useKeepAliveStore();
const router = useRouter();
const route = useRoute();
Expand Down Expand Up @@ -188,9 +190,11 @@
// logout({})
await userStore.logout();
}
message.success('成功退出登录');
keepAliveStore.clear();
// 移除标签页
localStorage.clear();
message.success('成功退出登录');
await nextTick();
router.replace({
name: LOGIN_NAME,
query: {
Expand Down
4 changes: 2 additions & 2 deletions src/layout/routerView/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<router-view v-slot="{ Component }">
<!-- <router-view v-slot="{ Component }">
<template v-if="Component">
<transition mode="out-in">
<suspense>
Expand All @@ -11,7 +11,7 @@
</suspense>
</transition>
</template>
</router-view>
</router-view> -->
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion src/router/generator-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const generatorDynamicRouter = (asyncMenus: API.Menu[]) => {
.getRoutes()
.filter(
(item) =>
(!item.children.length || Object.is(item.meta.hideChildrenInMenu, true)) &&
(!item.children.length || Object.is(item.meta?.hideChildrenInMenu, true)) &&
!outsideLayout.some((n) => n.name === item.name),
);
// 清空所有路由
Expand Down
5 changes: 5 additions & 0 deletions src/router/router-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function createRouterGuards(router: Router, whiteNameList: WhiteNameList)

router.afterEach((to, from, failure) => {
const keepAliveStore = useKeepAliveStore();
const token = Storage.get(ACCESS_TOKEN_KEY, null);

if (isNavigationFailure(failure)) {
console.error('failed navigation', failure);
Expand Down Expand Up @@ -92,6 +93,10 @@ export function createRouterGuards(router: Router, whiteNameList: WhiteNameList)
const componentName = getComponentName(from);
componentName && keepAliveStore.remove(componentName);
}
// 如果用户已登出,则清空所有缓存的组件
if (!token) {
keepAliveStore.clear();
}
NProgress.done(); // finish progress bar
});

Expand Down
2 changes: 1 addition & 1 deletion src/views/demos/tables/search-table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
...params,
});
// 手动设置搜索表单的搜索项
dynamicTableInstance?.getQueryFormRef()?.updateSchema([
dynamicTableInstance?.getQueryFormRef()?.updateSchema?.([
{
field: 'price',
componentProps: {
Expand Down
2 changes: 1 addition & 1 deletion src/views/demos/tables/wzry-table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
const { data } = await getWzryHeroList(params);
tableData = data.list;
dynamicTableInstance?.getQueryFormRef()?.updateSchema([
dynamicTableInstance?.getQueryFormRef()?.updateSchema?.([
{
field: 'skin_name',
componentProps: {
Expand Down
Loading

1 comment on commit 32c0a15

@vercel
Copy link

@vercel vercel bot commented on 32c0a15 Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vue3-antd-admin – ./

vue3-antd-admin-git-main-buqiyuan.vercel.app
vue3-antd-admin.vercel.app
vue3-antd-admin-buqiyuan.vercel.app

Please sign in to comment.