Skip to content

Commit

Permalink
feat: first version
Browse files Browse the repository at this point in the history
  • Loading branch information
williamc committed Jan 10, 2024
1 parent f7af0bb commit 765a68b
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 82 deletions.
68 changes: 56 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
# pkg-placeholder
# @deviltea/vue-router-middleware

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![License][license-src]][license-href]

_description_
A simple router middleware system implemented by beforeEach guard.

> **Note**:
> Replace `pkg-placeholder`, `repo-placeholder`, `_description_` and `deviltea` globally to use this template.
## Install

```bash
npm install @deviltea/vue-router-middleware
```

## Usage

```ts
import { createRouter, createWebHistory } from 'vue-router'
import { createHandleMiddlewares, defineMiddleware } from '@deviltea/vue-router-middleware'

const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
component: () => import('./views/Home.vue'),
meta: {
// The property "middleware" could be a function or an array of functions.
middleware: defineMiddleware((to, from) => {
// Do something
// Like a "beforeEnter" guard, if return false, the navigation will be aborted.
// If return another route, the navigation will be redirected to the route.
// If return nothing or true, it will continue to the next middleware.
// All of the things above work the same way with async functions and Promises.
})
}
},
// Example of using an array of functions.
{
path: '/',
component: () => import('./views/Home.vue'),
meta: {
middleware: [
middleware1,
middleware2,
middleware3
]
}
}
]
})

router.beforeEach(createHandleMiddlewares())
```

## License

Expand All @@ -17,11 +61,11 @@ _description_

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669
[npm-version-href]: https://npmjs.com/package/pkg-placeholder
[npm-downloads-src]: https://img.shields.io/npm/dm/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669
[npm-downloads-href]: https://npmjs.com/package/pkg-placeholder
[bundle-src]: https://img.shields.io/bundlephobia/minzip/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669&label=minzip
[bundle-href]: https://bundlephobia.com/result?p=pkg-placeholder
[license-src]: https://img.shields.io/github/license/DevilTea/repo-placeholder.svg?style=flat&colorA=080f12&colorB=1fa669
[license-href]: https://github.com/DevilTea/repo-placeholder/blob/main/LICENSE
[npm-version-src]: https://img.shields.io/npm/v/@deviltea/vue-router-middleware?style=flat&colorA=080f12&colorB=1fa669
[npm-version-href]: https://npmjs.com/package/@deviltea/vue-router-middleware
[npm-downloads-src]: https://img.shields.io/npm/dm/@deviltea/vue-router-middleware?style=flat&colorA=080f12&colorB=1fa669
[npm-downloads-href]: https://npmjs.com/package/@deviltea/vue-router-middleware
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@deviltea/vue-router-middleware?style=flat&colorA=080f12&colorB=1fa669&label=minzip
[bundle-href]: https://bundlephobia.com/result?p=@deviltea/vue-router-middleware
[license-src]: https://img.shields.io/github/license/DevilTea/vue-router-middleware.svg?style=flat&colorA=080f12&colorB=1fa669
[license-href]: https://github.com/DevilTea/vue-router-middleware/blob/main/LICENSE
3 changes: 3 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ export default defineBuildConfig({
clean: true,
rollup: {
emitCJS: true,
dts: {
tsconfig: './tsconfig.lib.json',
},
},
})
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "pkg-placeholder",
"name": "@deviltea/vue-router-middleware",
"type": "module",
"version": "0.0.0",
"packageManager": "[email protected]",
"description": "_description_",
"description": "A simple router middleware system implemented by beforeEnter guard.",
"author": "DevilTea <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/DevilTea/repo-placeholder#readme",
"homepage": "https://github.com/DevilTea/vue-router-middleware#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/DevilTea/repo-placeholder.git"
"url": "git+https://github.com/DevilTea/vue-router-middleware.git"
},
"bugs": "https://github.com/DevilTea/repo-placeholder/issues",
"bugs": "https://github.com/DevilTea/vue-router-middleware/issues",
"keywords": [],
"sideEffects": false,
"exports": {
Expand Down Expand Up @@ -52,6 +52,10 @@
"typecheck": "tsc --noEmit --project tsconfig.test.json",
"prepare": "simple-git-hooks"
},
"peerDependencies": {
"vue": ">=3.0.0",
"vue-router": ">=4.0.0"
},
"devDependencies": {
"@antfu/ni": "^0.21.12",
"@deviltea/eslint-config": "^3.0.0",
Expand All @@ -65,10 +69,12 @@
"pnpm": "^8.11.0",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.9.0",
"typescript": "^5.3.2",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.0.4",
"vitest": "^1.0.2"
"vitest": "^1.0.2",
"vue": "^3.3.13",
"vue-router": "^4.2.5"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
Expand Down
Loading

0 comments on commit 765a68b

Please sign in to comment.