Browse Source

路由守卫直接拦截src

master
蟑螂恶霸 3 years ago
parent
commit
cf6e9105cb
  1. 68
      src/common/globalRouter.js
  2. 1
      src/views/enforce/historyCheck.vue

68
src/common/globalRouter.js

@ -23,41 +23,45 @@ const $globalRouter = createRouter({
$globalExpandRouter($globalRouter, routes); // 添加路由扩展
$globalRouter.beforeEach((to, from, next) => {
// 在这里进行身份验证、权限检查等
// ...
let pattern3 = new RegExp("^[0-9]*$");
if (null != to.query) {
for (let key in to.query) {
if (pattern3.test(to.query[key])) {
if (to.query[key].toString().length > 9) {
to.query[key] = 0;
}
} else {
if (to.query[key].toString().length > 33) {
to.query[key] = "";
}
}
}
}
if (null != to.params) {
for (let key in to.params) {
if (pattern3.test(to.params[key])) {
if (to.params[key].toString().length > 9) {
to.params[key] = 0;
}
// let pattern3 = new RegExp("^[0-9]*$");
// if (null != to.query) {
// for (let key in to.query) {
// if (pattern3.test(to.query[key])) {
// if (to.query[key].toString().length > 9) {
// console.log(to.query[key])
// to.query[key] = 0;
// console.log(to.query[key])
// }
// } else {
// if (to.query[key].toString().length > 33) {
// to.query[key] = "";
// }
// }
// }
// }
//
// if (null != to.params) {
// for (let key in to.params) {
// if (pattern3.test(to.params[key])) {
// if (to.params[key].toString().length > 9) {
// to.params[key] = 0;
// }
// } else {
// if (to.params[key].toString().length > 33) {
// to.params[key] = "";
// }
// }
// }
// }
if (to.path.includes('src')) {
// 可以重定向或者做其他处理
next('/'); // 或者 next(from.path) 返回之前的路径
} else {
if (to.params[key].toString().length > 33) {
to.params[key] = "";
}
}
}
}
// 必须调用next()来resolve这个钩子。
// 可以传递'next()'、'next(false)'或者'next("/path")'来控制路由
next(); // 允许路由继续
// next(false); // 中断路由,并且不跳转到任何地方
// next("/path"); // 中断路由,并跳转到指定的路径
}
});
export { $globalRouter };

1
src/views/enforce/historyCheck.vue

@ -311,7 +311,6 @@
* @param {*} name
*/
const toDetailView = (id) =>{
console.log(id)
router.push(
{
path: "/registrationDetail",

Loading…
Cancel
Save