display page access history
Automatic record routes
Routes with the hidden
flag are automatically closed by default, this behavior can be prevented with keep-hidden-route
Use ref
bind Tabs
then execute internal methods to close tab
Do something before the tab add with the before-add
hook. If false
is returned or a Promise
is returned and then is rejected, add will be prevented.
Do something before the tab switch with the before-leave
hook. If false
is returned or a Promise
is returned and then is rejected, add will be prevented.
Customize the label content of the tab through label
TIP
Since 1.4.0, the label
slot parameter has been changed to RouteLocationNormalizedLoaded
Since 1.4.0, the Tabs component supports displaying the right-click menu through the contextmenu
configuration
TIP
If you enable the refresh
feature, you need to configure the refreshPath
attribute additionally and add the corresponding route information to vue-router
import {
createMemoryHistory,
createRouter as _createRouter,
createWebHistory,
Router,
} from 'vue-router'
import BaseLayout from '../layout/Layout.vue'
import enUS from './en-US'
import zhCN from './zh-CN'
import dev from './dev'
import { langs } from '../utils/index'
import type { RouteRecordRaw } from 'vue-router'
const routes: RouteRecordRaw[] = [
{
path: '/dev/refresh',
component: BaseLayout,
meta: { hidden: true },
children: [
{
path: '/dev/refresh',
component: () => import('../layout/Refresh.vue'),
meta: { hidden: true },
},
],
},
...enUS,
...zhCN,
]
export function createRouter(): Router {
const baseUrl = import.meta.env.BASE_URL
const router = _createRouter({
history: import.meta.env.SSR
? createMemoryHistory(baseUrl)
: createWebHistory(baseUrl),
routes: import.meta.env.MODE === 'production' ? routes : routes.concat(dev),
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
el: to.hash,
top: 94,
behavior: 'smooth',
})
}, 600) // Wait for the animation to finish
})
} else if (savedPosition) {
return savedPosition
} else {
return { top: 0 }
}
},
})
router.beforeEach((from) => {
if (from.path === '/') {
const lang = navigator.language
return langs.find((item) => item.key === lang) ? lang : langs[0].key
}
})
return router
}
Name | Description | Type | Accepted Values | Default |
---|---|---|---|---|
type | type of Tab | string | card / border-card | - |
tab-position | position of tabs | string | top / right / bottom / left | top |
stretch | whether width of tab automatically fits its container | boolean | - | false |
keep-hidden-route | Whether to keep the route with the hidden flag, it is automatically closed by default | boolean | - | false |
contextmenu | The right-click menu configuration | boolean / object ({ refresh?: boolean, left?: boolean, right?: boolean, others?: boolean }) | - | false |
refreshPath | Refresh path, used to refresh the tab page | string | - | - |
before-add | hook function before add tab. If false is returned or a Promise is returned and then is rejected, add will be prevented | Function({ route, oldPath, list, close, closeOther }) | - | - |
before-leave | hook function before switching tab. If false is returned or a Promise is returned and then is rejected, switching will be prevented | Function(activeName, oldActiveName) | - | - |
Name | Description | Type |
---|---|---|
tab-click | triggers when a tab is clicked | (pane: TabsPaneContext, ev: Event) => void |
tab-change | triggers when activeName is changed | (name: TabPaneName) => void |
tab-remove | triggers when tab-remove button is clicked | (name: TabPaneName) => void |
Name | Description | Type |
---|---|---|
list | access history list | Ref<RouteLocationNormalizedLoaded[]> |
close | close some tab from tabs | (path: string) => void |
closeOther | close other tab from tabs | () => void |
Name | Description | Type |
---|---|---|
label | customize the label content of the tab | RouteLocationNormalizedLoaded |