mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 完善路由配置
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import useAppTitle from './useAppTitle';
|
||||
import useCreateContext from './useCreateContext';
|
||||
import useRouterChange from './useRouterChange';
|
||||
import useRouteParam from './useRouteParam';
|
||||
|
||||
export { useAppTitle, useCreateContext, useRouterChange };
|
||||
export { useAppTitle, useCreateContext, useRouterChange, useRouteParam };
|
||||
|
20
src/hooks/common/useRouteParam.ts
Normal file
20
src/hooks/common/useRouteParam.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { RouteNameMap } from '@/router';
|
||||
|
||||
export default function useRouteParam() {
|
||||
const route = useRoute();
|
||||
|
||||
/** 登录跳转链接 */
|
||||
const loginRedirectUrl = computed(() => {
|
||||
let url = '';
|
||||
if (route.name === RouteNameMap.get('login')) {
|
||||
url = (route.params?.redirectUrl as string) ?? '';
|
||||
}
|
||||
return url;
|
||||
});
|
||||
|
||||
return {
|
||||
loginRedirectUrl
|
||||
};
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
import { useRouter } from 'vue-router';
|
||||
import { EnumRoutePaths } from '@/enum';
|
||||
import { EnumRoutePath } from '@/enum';
|
||||
import { RouteNameMap } from '@/router';
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
|
||||
export default function useRouterChange() {
|
||||
const router = useRouter();
|
||||
|
||||
/** 跳转首页 */
|
||||
function toHome() {
|
||||
router.push('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转登录页面(通过vue路由)
|
||||
* @param module - 展示的登录模块
|
||||
@ -28,7 +33,7 @@ export default function useRouterChange() {
|
||||
* @param redirectUrl - 登录后重定向的页面路径
|
||||
*/
|
||||
function toLoginByLocation(module: LoginModuleType = 'pwd-login', redirectUrl?: string) {
|
||||
let href = `${window.location.origin + EnumRoutePaths.login}/${module}`;
|
||||
let href = `${window.location.origin + EnumRoutePath.login}/${module}`;
|
||||
if (redirectUrl) {
|
||||
href += redirectUrl;
|
||||
}
|
||||
@ -36,6 +41,7 @@ export default function useRouterChange() {
|
||||
}
|
||||
|
||||
return {
|
||||
toHome,
|
||||
toLogin,
|
||||
toLoginByLocation
|
||||
};
|
||||
|
Reference in New Issue
Block a user