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 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,90 +14,115 @@ 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
+ 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: "Home",
52
- icon: "fa fa-home",
53
- key: "fullPath",
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: "/about",
67
+ path: '/about',
60
68
  component: About,
61
69
  meta: {
62
- title: "About",
63
- icon: "fa fa-info-circle",
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 built-in shortcuts `fullPath`, `path`, or `name`, or you can supply a custom function.
78
+ `meta.key` accepts the shortcuts `fullPath`, `path`, or `name`, or you can supply your own function.
71
79
 
72
- ## Pinia persistence
80
+ ## Cookie persistence
73
81
 
74
- `<router-tabs>` wraps `useRouterTabsPiniaPersistence` and synchronises the tab snapshot with Pinia/localStorage. You can configure it through props:
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-tabs
78
- storage-key="app-tabs" <!-- storage key name -->
79
- :fallback-route="'/dashboard'" <!-- optional route used when no snapshot exists -->
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
- Prefer to use the composable directly?
96
+ Want to wire it up yourself?
84
97
 
85
98
  ```ts
86
99
  <script setup lang="ts">
87
- import { useRouterTabsPiniaPersistence } from 'vue3-router-tab'
100
+ import { useRouterTabsPersistence } from 'vue3-router-tab'
88
101
 
89
- useRouterTabsPiniaPersistence({
90
- storageKey: 'app-tabs',
91
- fallbackRoute: '/dashboard',
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
- You can provide your own Pinia store via the `store` option if you need to persist snapshots to a backend or IndexedDB.
111
+ ### Custom rendering
97
112
 
98
- ## Customising the context menu
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
- The context menu can be disabled or extended via the `contextmenu` prop:
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: 'my-action',
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 hide the menu entirely.
142
+ Pass `false` to disable the context menu entirely.
118
143
 
119
144
  ## Slots
120
145
 
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)
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 SCSS/CSS bundle (imported automatically by the plugin). To customise, override the classes prefixed with `router-tab__` in your own CSS.
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 "vue3-router-tab";
156
+ import type { TabRecord, RouterTabsSnapshot, RouterTabsPersistenceOptions } from 'vue3-router-tab'
134
157
  ```
135
158
 
136
159
  ## License