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.
vite-vue3-lowcode/preview/router.ts

36 lines
915 B

/*
* @Author:
* @Date: 2021-06-01 09:45:21
* @LastEditTime: 2021-06-25 08:47:07
* @LastEditors:
* @Description:
* @FilePath: \vite-vue3-lowcode\preview\router.ts
*/
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import type { VisualEditorModelValue } from '@/visual-editor/visual-editor.utils';
import { CacheEnum } from '@/enums';
const routes: Array<RouteRecordRaw> = [
{
path: '/:pathMatch(.*)*',
component: () => import('./views/preview.vue'),
},
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
// 获取本地缓存的页面数据
const jsonData: VisualEditorModelValue = JSON.parse(
localStorage.getItem(CacheEnum.PAGE_DATA_KEY) as string,
);
router.beforeEach((to) => {
document.title = jsonData?.pages?.[to.path]?.title ?? document.title;
return true;
});
export default router;