@aerogel/plugin-routing 0.0.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/.eslintrc.js +7 -0
- package/dist/aerogel-plugin-routing.cjs.js +2 -0
- package/dist/aerogel-plugin-routing.cjs.js.map +1 -0
- package/dist/aerogel-plugin-routing.d.ts +12 -0
- package/dist/aerogel-plugin-routing.esm.js +2 -0
- package/dist/aerogel-plugin-routing.esm.js.map +1 -0
- package/package.json +42 -0
- package/src/main.ts +22 -0
- package/src/router.ts +21 -0
- package/tsconfig.json +4 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@noeldemartin/utils"),t=require("vue-router");function r(r){const o=t.createRouter({history:t.createWebHistory(r.basePath),routes:r.routes});return o.beforeEach(e.once((()=>function(t){const r=e.Storage.pull("static-404-redirect");r&&t.replace(r)}(o)))),o}exports.default=function(e){return{install(t){const o=r({routes:e.routes,basePath:e.basePath??__AG_BASE_PATH});t.use(o)}}};
|
|
2
|
+
//# sourceMappingURL=aerogel-plugin-routing.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aerogel-plugin-routing.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin as Plugin_2 } from '@aerogel/core';
|
|
2
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
3
|
+
|
|
4
|
+
declare interface Options {
|
|
5
|
+
routes: RouteRecordRaw[];
|
|
6
|
+
basePath?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare function routing(options: Options): Plugin_2;
|
|
10
|
+
export default routing;
|
|
11
|
+
|
|
12
|
+
export { }
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{once as t,Storage as e}from"@noeldemartin/utils";import{createRouter as r,createWebHistory as o}from"vue-router";function s(s){const u=r({history:o(s.basePath),routes:s.routes});return u.beforeEach(t((()=>function(t){const r=e.pull("static-404-redirect");r&&t.replace(r)}(u)))),u}function u(t){return{install(e){const r=s({routes:t.routes,basePath:t.basePath??__AG_BASE_PATH});e.use(r)}}}export{u as default};
|
|
2
|
+
//# sourceMappingURL=aerogel-plugin-routing.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aerogel-plugin-routing.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aerogel/plugin-routing",
|
|
3
|
+
"description": "Aerogel routing plugin",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"main": "dist/aerogel-plugin-routing.cjs.js",
|
|
6
|
+
"module": "dist/aerogel-plugin-routing.esm.js",
|
|
7
|
+
"types": "dist/aerogel-plugin-routing.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm dist -rf && npm run build:js && npm run build:types",
|
|
11
|
+
"build:js": "noeldemartin-build-javascript",
|
|
12
|
+
"build:types": "noeldemartin-build-types",
|
|
13
|
+
"publish-next": "noeldemartin-publish-next",
|
|
14
|
+
"lint": "noeldemartin-lint src"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.x"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/NoelDeMartin/aerogeljs.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"javascript",
|
|
25
|
+
"aerogel"
|
|
26
|
+
],
|
|
27
|
+
"author": "Noel De Martin",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/NoelDeMartin/aerogeljs/issues"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@aerogel/core": "*"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@noeldemartin/utils": "0.4.0-next.ac00beaecf32bb02ed8e335225d7948d946d73bd",
|
|
37
|
+
"vue-router": "^4.2.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@aerogel/core": "*"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from '@aerogel/core';
|
|
2
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
3
|
+
|
|
4
|
+
import { createAppRouter } from './router';
|
|
5
|
+
|
|
6
|
+
interface Options {
|
|
7
|
+
routes: RouteRecordRaw[];
|
|
8
|
+
basePath?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function routing(options: Options): Plugin {
|
|
12
|
+
return {
|
|
13
|
+
install(app) {
|
|
14
|
+
const plugin = createAppRouter({
|
|
15
|
+
routes: options.routes,
|
|
16
|
+
basePath: options.basePath ?? __AG_BASE_PATH,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.use(plugin);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
package/src/router.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Storage, once } from '@noeldemartin/utils';
|
|
2
|
+
import { createRouter, createWebHistory } from 'vue-router';
|
|
3
|
+
import type { Plugin } from 'vue';
|
|
4
|
+
import type { RouteLocationRaw, RouteRecordRaw, Router } from 'vue-router';
|
|
5
|
+
|
|
6
|
+
function handleStatic404Redirect(router: Router): void {
|
|
7
|
+
const route = Storage.pull<RouteLocationRaw>('static-404-redirect');
|
|
8
|
+
|
|
9
|
+
route && router.replace(route);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createAppRouter(options: { routes: RouteRecordRaw[]; basePath?: string }): Plugin {
|
|
13
|
+
const router = createRouter({
|
|
14
|
+
history: createWebHistory(options.basePath),
|
|
15
|
+
routes: options.routes,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
router.beforeEach(once(() => handleStatic404Redirect(router)));
|
|
19
|
+
|
|
20
|
+
return router;
|
|
21
|
+
}
|
package/tsconfig.json
ADDED