vue3-router-tab 1.0.0 → 1.0.2
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 +125 -31
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -1,44 +1,138 @@
|
|
|
1
|
-
#
|
|
2
|
-
Based on [vue-snotify](https://github.com/artemsky/vue-snotify) for Vue 2.
|
|
1
|
+
# vue3-router-tab
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
A Vue 3 tab-bar plugin that keeps multiple routes alive with transition support, context menus, and optional Pinia persistence.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install vue3-router-tab
|
|
9
|
+
# or
|
|
10
|
+
pnpm add vue3-router-tab
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Register the plugin
|
|
6
14
|
|
|
7
|
-
In main.ts :
|
|
8
15
|
```ts
|
|
9
|
-
|
|
16
|
+
// main.ts
|
|
17
|
+
import { createApp } from "vue";
|
|
18
|
+
import App from "./App.vue";
|
|
19
|
+
import router from "./router";
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
import RouterTab from "vue3-router-tab";
|
|
12
22
|
|
|
13
|
-
app
|
|
23
|
+
const app = createApp(App);
|
|
24
|
+
app.use(router);
|
|
25
|
+
app.use(RouterTab);
|
|
26
|
+
app.mount("#app");
|
|
27
|
+
```
|
|
14
28
|
|
|
15
|
-
|
|
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)
|
|
33
|
+
|
|
34
|
+
## Basic usage
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<template>
|
|
38
|
+
<router-tab> </router-tab>
|
|
39
|
+
</template>
|
|
16
40
|
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
41
|
+
|
|
42
|
+
Configure the routes with meta information to control titles, icons, and whether a tab can be closed:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// router.ts
|
|
46
|
+
const routes = [
|
|
47
|
+
{
|
|
48
|
+
path: "/",
|
|
49
|
+
component: Home,
|
|
50
|
+
meta: {
|
|
51
|
+
title: "Home",
|
|
52
|
+
icon: "fa fa-home",
|
|
53
|
+
key: "fullPath",
|
|
54
|
+
closable: true,
|
|
55
|
+
keepAlive: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
path: "/about",
|
|
60
|
+
component: About,
|
|
61
|
+
meta: {
|
|
62
|
+
title: "About",
|
|
63
|
+
icon: "fa fa-info-circle",
|
|
64
|
+
keepAlive: false,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
];
|
|
20
68
|
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
69
|
+
|
|
70
|
+
`meta.key` accepts the built-in shortcuts `fullPath`, `path`, or `name`, or you can supply a custom function.
|
|
71
|
+
|
|
72
|
+
## Pinia persistence
|
|
73
|
+
|
|
74
|
+
`<router-tabs>` wraps `useRouterTabsPiniaPersistence` and synchronises the tab snapshot with Pinia/localStorage. You can configure it through props:
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<router-tabs
|
|
78
|
+
storage-key="app-tabs" <!-- storage key name -->
|
|
79
|
+
:fallback-route="'/dashboard'" <!-- optional route used when no snapshot exists -->
|
|
80
|
+
/>
|
|
28
81
|
```
|
|
29
|
-
## Inject function for Vue files
|
|
30
|
-
The plugin automatically sets global provide() with key "vue3-notify".
|
|
31
|
-
```js
|
|
32
|
-
<script setup>
|
|
33
|
-
import { inject } from "vue";
|
|
34
82
|
|
|
35
|
-
|
|
83
|
+
Prefer to use the composable directly?
|
|
36
84
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
};
|
|
85
|
+
```ts
|
|
86
|
+
<script setup lang="ts">
|
|
87
|
+
import { useRouterTabsPiniaPersistence } from 'vue3-router-tab'
|
|
42
88
|
|
|
89
|
+
useRouterTabsPiniaPersistence({
|
|
90
|
+
storageKey: 'app-tabs',
|
|
91
|
+
fallbackRoute: '/dashboard',
|
|
92
|
+
})
|
|
43
93
|
</script>
|
|
44
|
-
```
|
|
94
|
+
```
|
|
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
|
+
|
|
98
|
+
## Customising the context menu
|
|
99
|
+
|
|
100
|
+
The context menu can be disabled or extended via the `contextmenu` prop:
|
|
101
|
+
|
|
102
|
+
```vue
|
|
103
|
+
<router-tab
|
|
104
|
+
:contextmenu="[
|
|
105
|
+
'refresh',
|
|
106
|
+
'close',
|
|
107
|
+
{ id: 'closeOthers', label: 'Close All Others' },
|
|
108
|
+
{
|
|
109
|
+
id: 'my-action',
|
|
110
|
+
label: 'Open in new window',
|
|
111
|
+
handler: ({ target }) => window.open(target.to, '_blank'),
|
|
112
|
+
},
|
|
113
|
+
]"
|
|
114
|
+
/>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Pass `false` to hide the menu entirely.
|
|
118
|
+
|
|
119
|
+
## Slots
|
|
120
|
+
|
|
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)
|
|
123
|
+
|
|
124
|
+
## Styling
|
|
125
|
+
|
|
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.
|
|
127
|
+
|
|
128
|
+
## Types
|
|
129
|
+
|
|
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
|
+
```ts
|
|
133
|
+
import type { TabRecord, RouterTabsSnapshot } from "vue3-router-tab";
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue3-router-tab",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
29
|
-
"pinia": "^
|
|
29
|
+
"pinia": "^3.0.3",
|
|
30
30
|
"sass": "^1.93.2",
|
|
31
31
|
"sass-loader": "^16.0.5",
|
|
32
32
|
"typescript": "^5.9.2",
|
|
@@ -39,7 +39,11 @@
|
|
|
39
39
|
"vue3",
|
|
40
40
|
"router",
|
|
41
41
|
"tabs",
|
|
42
|
-
"tab"
|
|
42
|
+
"tab",
|
|
43
|
+
"pinia",
|
|
44
|
+
"persistence",
|
|
45
|
+
"tab persistence",
|
|
46
|
+
"router-tab"
|
|
43
47
|
],
|
|
44
48
|
"license": "MIT",
|
|
45
49
|
"homepage": "https://github.com/anilshr25/vue3-router-tab/#readme",
|