vue3-router-tab 1.0.9 → 1.1.1
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 +72 -49
- package/dist/vue3-router-tab.js +450 -574
- package/dist/vue3-router-tab.umd.cjs +1 -12
- package/lib/components/RouterTab.vue +54 -98
- 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 +11 -8
- package/index.d.ts +0 -134
- 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,90 +14,115 @@ 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
|
-
|
|
39
|
+
Need to customise the rendered output? Provide a slot and use the routed component directly—see [`example-app/src/App.vue`](example-app/src/App.vue) for a working sample:
|
|
40
|
+
|
|
41
|
+
```vue
|
|
42
|
+
<router-tab cookie-key="app-tabs">
|
|
43
|
+
<template #default="{ Component, route }">
|
|
44
|
+
<Suspense>
|
|
45
|
+
<component :is="Component" :key="route.fullPath" />
|
|
46
|
+
</Suspense>
|
|
47
|
+
</template>
|
|
48
|
+
</router-tab>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Configure route metadata to control tab labels, icons, and lifecycle behaviour:
|
|
43
52
|
|
|
44
53
|
```ts
|
|
45
|
-
// router.ts
|
|
46
54
|
const routes = [
|
|
47
55
|
{
|
|
48
|
-
path:
|
|
56
|
+
path: '/',
|
|
49
57
|
component: Home,
|
|
50
58
|
meta: {
|
|
51
|
-
title:
|
|
52
|
-
icon:
|
|
53
|
-
key:
|
|
59
|
+
title: 'Home',
|
|
60
|
+
icon: 'fa fa-home',
|
|
61
|
+
key: 'fullPath',
|
|
54
62
|
closable: true,
|
|
55
63
|
keepAlive: true,
|
|
56
64
|
},
|
|
57
65
|
},
|
|
58
66
|
{
|
|
59
|
-
path:
|
|
67
|
+
path: '/about',
|
|
60
68
|
component: About,
|
|
61
69
|
meta: {
|
|
62
|
-
title:
|
|
63
|
-
icon:
|
|
70
|
+
title: 'About',
|
|
71
|
+
icon: 'fa fa-info-circle',
|
|
64
72
|
keepAlive: false,
|
|
65
73
|
},
|
|
66
74
|
},
|
|
67
|
-
]
|
|
75
|
+
]
|
|
68
76
|
```
|
|
69
77
|
|
|
70
|
-
`meta.key` accepts the
|
|
78
|
+
`meta.key` accepts the shortcuts `fullPath`, `path`, or `name`, or you can supply your own function.
|
|
71
79
|
|
|
72
|
-
##
|
|
80
|
+
## Cookie persistence
|
|
73
81
|
|
|
74
|
-
`<router-
|
|
82
|
+
`<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
83
|
|
|
76
84
|
```vue
|
|
77
|
-
<router-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
<router-tab>
|
|
86
|
+
<template #start>
|
|
87
|
+
<router-tabs
|
|
88
|
+
cookie-key="app-tabs"
|
|
89
|
+
:expires-in-days="14"
|
|
90
|
+
fallback-route="/dashboard"
|
|
91
|
+
/>
|
|
92
|
+
</template>
|
|
93
|
+
</router-tab>
|
|
81
94
|
```
|
|
82
95
|
|
|
83
|
-
|
|
96
|
+
Want to wire it up yourself?
|
|
84
97
|
|
|
85
98
|
```ts
|
|
86
99
|
<script setup lang="ts">
|
|
87
|
-
import {
|
|
100
|
+
import { useRouterTabsPersistence } from 'vue3-router-tab'
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
useRouterTabsPersistence({
|
|
103
|
+
cookieKey: 'app-tabs',
|
|
104
|
+
expiresInDays: 30,
|
|
105
|
+
fallbackRoute: '/dashboard'
|
|
92
106
|
})
|
|
93
107
|
</script>
|
|
94
108
|
```
|
|
109
|
+
The composable also exposes `serialize` / `deserialize` options so you can encrypt or customise the cookie payload.
|
|
95
110
|
|
|
96
|
-
|
|
111
|
+
### Custom rendering
|
|
97
112
|
|
|
98
|
-
|
|
113
|
+
You can override the default routed view by providing a `#default` slot. The slot receives the same values you would normally get from `<RouterView v-slot>`:
|
|
99
114
|
|
|
100
|
-
|
|
115
|
+
```vue
|
|
116
|
+
<router-tab cookie-key="app-tabs">
|
|
117
|
+
<template #default="{ Component, route }">
|
|
118
|
+
<Suspense>
|
|
119
|
+
<component :is="Component" :key="route.fullPath" />
|
|
120
|
+
</Suspense>
|
|
121
|
+
</template>
|
|
122
|
+
</router-tab>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Customising the context menu
|
|
101
126
|
|
|
102
127
|
```vue
|
|
103
128
|
<router-tab
|
|
@@ -106,31 +131,29 @@ The context menu can be disabled or extended via the `contextmenu` prop:
|
|
|
106
131
|
'close',
|
|
107
132
|
{ id: 'closeOthers', label: 'Close All Others' },
|
|
108
133
|
{
|
|
109
|
-
id: '
|
|
134
|
+
id: 'openWindow',
|
|
110
135
|
label: 'Open in new window',
|
|
111
|
-
handler: ({ target }) => window.open(target.to, '_blank')
|
|
112
|
-
}
|
|
136
|
+
handler: ({ target }) => window.open(target.to, '_blank')
|
|
137
|
+
}
|
|
113
138
|
]"
|
|
114
139
|
/>
|
|
115
140
|
```
|
|
116
141
|
|
|
117
|
-
Pass `false` to
|
|
142
|
+
Pass `false` to disable the context menu entirely.
|
|
118
143
|
|
|
119
144
|
## Slots
|
|
120
145
|
|
|
121
|
-
- `start` / `end` –
|
|
122
|
-
- `default` –
|
|
146
|
+
- `start` / `end` – positioned on either side of the tab list (ideal for toolbars or the `<router-tabs>` helper).
|
|
147
|
+
- `default` – routed content (rendered automatically by `<router-tab>`).
|
|
123
148
|
|
|
124
149
|
## Styling
|
|
125
150
|
|
|
126
|
-
The package ships with its own
|
|
151
|
+
The package ships with its own CSS bundle (imported automatically). Override the `router-tab__*` classes in your stylesheet to customise the appearance.
|
|
127
152
|
|
|
128
153
|
## Types
|
|
129
154
|
|
|
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
155
|
```ts
|
|
133
|
-
import type { TabRecord, RouterTabsSnapshot } from
|
|
156
|
+
import type { TabRecord, RouterTabsSnapshot, RouterTabsPersistenceOptions } from 'vue3-router-tab'
|
|
134
157
|
```
|
|
135
158
|
|
|
136
159
|
## License
|