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 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 Pinia persistence.
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 "vue";
18
- import App from "./App.vue";
19
- import router from "./router";
17
+ import { createApp } from 'vue'
18
+ import App from './App.vue'
19
+ import router from './router'
20
20
 
21
- import RouterTab from "vue3-router-tab";
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("#app");
23
+ const app = createApp(App)
24
+ app.use(router)
25
+ app.use(RouterTab)
26
+ app.mount('#app')
27
27
  ```
28
28
 
29
- The plugin automatically registers two components globally:
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> </router-tab>
35
+ <router-tab cookie-key="app-tabs" />
39
36
  </template>
40
37
  ```
41
38
 
42
- Configure the routes with meta information to control titles, icons, and whether a tab can be closed:
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: "Home",
52
- icon: "fa fa-home",
53
- key: "fullPath",
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: "/about",
55
+ path: '/about',
60
56
  component: About,
61
57
  meta: {
62
- title: "About",
63
- icon: "fa fa-info-circle",
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 built-in shortcuts `fullPath`, `path`, or `name`, or you can supply a custom function.
66
+ `meta.key` accepts the shortcuts `fullPath`, `path`, or `name`, or you can supply your own function.
71
67
 
72
- ## Pinia persistence
68
+ ## Cookie persistence
73
69
 
74
- `<router-tabs>` wraps `useRouterTabsPiniaPersistence` and synchronises the tab snapshot with Pinia/localStorage. You can configure it through props:
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-tabs
78
- storage-key="app-tabs" <!-- storage key name -->
79
- :fallback-route="'/dashboard'" <!-- optional route used when no snapshot exists -->
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
- Prefer to use the composable directly?
84
+ Want to wire it up yourself?
84
85
 
85
86
  ```ts
86
87
  <script setup lang="ts">
87
- import { useRouterTabsPiniaPersistence } from 'vue3-router-tab'
88
+ import { useRouterTabsPersistence } from 'vue3-router-tab'
88
89
 
89
- useRouterTabsPiniaPersistence({
90
- storageKey: 'app-tabs',
91
- fallbackRoute: '/dashboard',
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: 'my-action',
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 hide the menu entirely.
116
+ Pass `false` to disable the context menu entirely.
118
117
 
119
118
  ## Slots
120
119
 
121
- - `start` / `end` – areas on either side of the tab list (useful for toolbars and the Pinia helper)
122
- - `default` – the routed tab content (provided by `<router-tab>` automatically)
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 SCSS/CSS bundle (imported automatically by the plugin). To customise, override the classes prefixed with `router-tab__` in your own CSS.
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 "vue3-router-tab";
130
+ import type { TabRecord, RouterTabsSnapshot, RouterTabsPersistenceOptions } from 'vue3-router-tab'
134
131
  ```
135
132
 
136
133
  ## License