vue3-router-tab 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -50
- package/dist/vue3-router-tab.js +479 -500
- package/dist/vue3-router-tab.umd.cjs +5 -5
- package/index.d.ts +25 -13
- package/lib/components/RouterTab.vue +19 -71
- package/lib/components/RouterTabs.vue +14 -0
- package/lib/constants.ts +2 -0
- package/lib/core/types.ts +12 -0
- package/lib/index.ts +9 -11
- package/lib/persistence.ts +171 -0
- package/package.json +5 -2
- package/lib/components/RouterTabsPinia.vue +0 -13
- package/lib/pinia.ts +0 -149
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# vue3-router-tab
|
|
2
2
|
|
|
3
|
-
A Vue 3 tab-bar plugin that keeps multiple routes alive with transition support, context menus, and optional
|
|
3
|
+
A Vue 3 tab-bar plugin that keeps multiple routes alive with transition support, context menus, and optional cookie-based persistence.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,91 +14,90 @@ pnpm add vue3-router-tab
|
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
// main.ts
|
|
17
|
-
import { createApp } from
|
|
18
|
-
import App from
|
|
19
|
-
import router from
|
|
17
|
+
import { createApp } from 'vue'
|
|
18
|
+
import App from './App.vue'
|
|
19
|
+
import router from './router'
|
|
20
20
|
|
|
21
|
-
import RouterTab from
|
|
21
|
+
import RouterTab from 'vue3-router-tab'
|
|
22
22
|
|
|
23
|
-
const app = createApp(App)
|
|
24
|
-
app.use(router)
|
|
25
|
-
app.use(RouterTab)
|
|
26
|
-
app.mount(
|
|
23
|
+
const app = createApp(App)
|
|
24
|
+
app.use(router)
|
|
25
|
+
app.use(RouterTab)
|
|
26
|
+
app.mount('#app')
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
The plugin
|
|
30
|
-
|
|
31
|
-
- `<router-tab>` – the tab layout and router-view wrapper
|
|
32
|
-
- `<router-tabs>` – a helper to persist tabs through Pinia/localStorage (optional)
|
|
29
|
+
The plugin registers the `<router-tab>` component globally. It also exposes an optional `<router-tabs>` helper for advanced cookie options, but you rarely need it now that persistence can be enabled directly on the tab component.
|
|
33
30
|
|
|
34
31
|
## Basic usage
|
|
35
32
|
|
|
36
33
|
```vue
|
|
37
34
|
<template>
|
|
38
|
-
<router-tab
|
|
35
|
+
<router-tab cookie-key="app-tabs" />
|
|
39
36
|
</template>
|
|
40
37
|
```
|
|
41
38
|
|
|
42
|
-
Configure
|
|
39
|
+
Configure route metadata to control tab labels, icons, and lifecycle behaviour:
|
|
43
40
|
|
|
44
41
|
```ts
|
|
45
|
-
// router.ts
|
|
46
42
|
const routes = [
|
|
47
43
|
{
|
|
48
|
-
path:
|
|
44
|
+
path: '/',
|
|
49
45
|
component: Home,
|
|
50
46
|
meta: {
|
|
51
|
-
title:
|
|
52
|
-
icon:
|
|
53
|
-
key:
|
|
47
|
+
title: 'Home',
|
|
48
|
+
icon: 'fa fa-home',
|
|
49
|
+
key: 'fullPath',
|
|
54
50
|
closable: true,
|
|
55
51
|
keepAlive: true,
|
|
56
52
|
},
|
|
57
53
|
},
|
|
58
54
|
{
|
|
59
|
-
path:
|
|
55
|
+
path: '/about',
|
|
60
56
|
component: About,
|
|
61
57
|
meta: {
|
|
62
|
-
title:
|
|
63
|
-
icon:
|
|
58
|
+
title: 'About',
|
|
59
|
+
icon: 'fa fa-info-circle',
|
|
64
60
|
keepAlive: false,
|
|
65
61
|
},
|
|
66
62
|
},
|
|
67
|
-
]
|
|
63
|
+
]
|
|
68
64
|
```
|
|
69
65
|
|
|
70
|
-
`meta.key` accepts the
|
|
66
|
+
`meta.key` accepts the shortcuts `fullPath`, `path`, or `name`, or you can supply your own function.
|
|
71
67
|
|
|
72
|
-
##
|
|
68
|
+
## Cookie persistence
|
|
73
69
|
|
|
74
|
-
`<router-
|
|
70
|
+
`<router-tab cookie-key="…" />` is usually all you need. If you prefer fine grained control (custom expiry, same-site, etc.) you can still use the headless helper:
|
|
75
71
|
|
|
76
72
|
```vue
|
|
77
|
-
<router-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
<router-tab>
|
|
74
|
+
<template #start>
|
|
75
|
+
<router-tabs
|
|
76
|
+
cookie-key="app-tabs"
|
|
77
|
+
:expires-in-days="14"
|
|
78
|
+
fallback-route="/dashboard"
|
|
79
|
+
/>
|
|
80
|
+
</template>
|
|
81
|
+
</router-tab>
|
|
81
82
|
```
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
Want to wire it up yourself?
|
|
84
85
|
|
|
85
86
|
```ts
|
|
86
87
|
<script setup lang="ts">
|
|
87
|
-
import {
|
|
88
|
+
import { useRouterTabsPersistence } from 'vue3-router-tab'
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
useRouterTabsPersistence({
|
|
91
|
+
cookieKey: 'app-tabs',
|
|
92
|
+
expiresInDays: 30,
|
|
93
|
+
fallbackRoute: '/dashboard'
|
|
92
94
|
})
|
|
93
95
|
</script>
|
|
94
96
|
```
|
|
95
|
-
|
|
96
|
-
You can provide your own Pinia store via the `store` option if you need to persist snapshots to a backend or IndexedDB.
|
|
97
|
+
The composable also exposes `serialize` / `deserialize` options so you can encrypt or customise the cookie payload.
|
|
97
98
|
|
|
98
99
|
## Customising the context menu
|
|
99
100
|
|
|
100
|
-
The context menu can be disabled or extended via the `contextmenu` prop:
|
|
101
|
-
|
|
102
101
|
```vue
|
|
103
102
|
<router-tab
|
|
104
103
|
:contextmenu="[
|
|
@@ -106,31 +105,29 @@ The context menu can be disabled or extended via the `contextmenu` prop:
|
|
|
106
105
|
'close',
|
|
107
106
|
{ id: 'closeOthers', label: 'Close All Others' },
|
|
108
107
|
{
|
|
109
|
-
id: '
|
|
108
|
+
id: 'openWindow',
|
|
110
109
|
label: 'Open in new window',
|
|
111
|
-
handler: ({ target }) => window.open(target.to, '_blank')
|
|
112
|
-
}
|
|
110
|
+
handler: ({ target }) => window.open(target.to, '_blank')
|
|
111
|
+
}
|
|
113
112
|
]"
|
|
114
113
|
/>
|
|
115
114
|
```
|
|
116
115
|
|
|
117
|
-
Pass `false` to
|
|
116
|
+
Pass `false` to disable the context menu entirely.
|
|
118
117
|
|
|
119
118
|
## Slots
|
|
120
119
|
|
|
121
|
-
- `start` / `end` –
|
|
122
|
-
- `default` –
|
|
120
|
+
- `start` / `end` – positioned on either side of the tab list (ideal for toolbars or the `<router-tabs>` helper).
|
|
121
|
+
- `default` – routed content (rendered automatically by `<router-tab>`).
|
|
123
122
|
|
|
124
123
|
## Styling
|
|
125
124
|
|
|
126
|
-
The package ships with its own
|
|
125
|
+
The package ships with its own CSS bundle (imported automatically). Override the `router-tab__*` classes in your stylesheet to customise the appearance.
|
|
127
126
|
|
|
128
127
|
## Types
|
|
129
128
|
|
|
130
|
-
The library ships TypeScript definitions for the tab records, menu configuration, Pinia options, and helper APIs. Import the types from the root module:
|
|
131
|
-
|
|
132
129
|
```ts
|
|
133
|
-
import type { TabRecord, RouterTabsSnapshot } from
|
|
130
|
+
import type { TabRecord, RouterTabsSnapshot, RouterTabsPersistenceOptions } from 'vue3-router-tab'
|
|
134
131
|
```
|
|
135
132
|
|
|
136
133
|
## License
|