You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

3 years ago
import { createRouter, createWebHashHistory } from "vue-router";
let routes = [
{
path: "/",
redirect: "/login",
name: "App",
},
{
path: "/:pathMatch(.*)*",
name: "404",
component: () => import("@/views/404"),
},
];
routes = $globalRouterModules(routes); // 加载模块路由
const $globalRouter = createRouter({
history: createWebHashHistory(),
routes,
});
$globalExpandRouter($globalRouter, routes); // 添加路由扩展
$globalRouter.beforeEach((to, from, next) => {
// 在这里进行身份验证、权限检查等
// ...
if (null != to.query) {
for (let key in to.query) {
if (typeof to.query[key] === 'number' && !Number.isNaN(to.query[key])) {
if (to.query[key].toString().length > 9) {
to.query[key] = 0;
console.log(to.query[key]);
}
}
}
}
if (null != to.params) {
for (let key in to.params) {
if (typeof to.params[key] === 'number' && !Number.isNaN(to.params[key])) {
if (to.params[key].toString().length > 9) {
to.params[key] = 0;
console.log(to.params[key]);
}
}
}
}
// 必须调用next()来resolve这个钩子。
// 可以传递'next()'、'next(false)'或者'next("/path")'来控制路由
next(); // 允许路由继续
// next(false); // 中断路由,并且不跳转到任何地方
// next("/path"); // 中断路由,并跳转到指定的路径
});
3 years ago
export { $globalRouter };