fix: 完善路由文件命名提示 & 保证403和404路由一直有权限 (#186)

* fix: 完善提示

* refactor: 切换路由都判断下403和404保证他们有权限
This commit is contained in:
听海 2023-04-11 20:38:54 +08:00 committed by GitHub
parent a670c5e10e
commit 29f925b644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -7,11 +7,15 @@ if (!accessApi) {
throw new Error('[plugin-layout]: plugin-layout depends on plugin-accessplease install plugin-access first');
}
const accessIds = accessApi.getAccess();
accessApi.setAccess(accessIds.concat(['/403', '/404']));
export const access = (memo) => {
const runtimeConfig = getConfig();
const accessIds = accessApi.getAccess();
if (!accessIds.includes('/403')) {
accessApi.setAccess(accessIds.concat('/403'));
}
if (!accessIds.includes('/404')) {
accessApi.setAccess(accessIds.concat('/404'));
}
return {
unAccessHandler({ router, to, from, next }) {
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {

View File

@ -55,12 +55,12 @@ const getRoutePath = function (parentRoutePath, fileName, isFile = true) {
}
// /@id.vue -> /:id
if (fileName.startsWith('@')) {
logger.warn(`[WARNING]: ${fileName} is deprecated, please use [slug]`);
logger.warn(`[WARNING]: filename or directory ${fileName} is deprecated, please use [${fileName.replace(/@/, '')}]`);
fileName = fileName.replace(/@/, ':');
}
// /*.vue -> :pathMatch(.*)
if (fileName.includes('*')) {
logger.warn(`[WARNING]: ${fileName} is deprecated, please use [...slug]`);
logger.warn(`[WARNING]: filename or directory ${fileName} is deprecated, please use ${fileName.replace('*', '[...]')}`);
fileName = fileName.replace('*', ':pathMatch(.*)');
}
// /[slug].vue -> /:slug