Browse Source

修改分享标题

Zenas 1 week ago
parent
commit
7e935ebfa6
2 changed files with 31 additions and 5 deletions
  1. 31 4
      src/router/index.ts
  2. 0 1
      src/router/routes/basic.ts

+ 31 - 4
src/router/index.ts

@@ -23,10 +23,37 @@ export const router = createRouter({
 
 // TODO 【QQYUN-4517】【表单设计器】记录分享路由守卫测试
 router.beforeEach(async (to, from, next) => {
-  //console.group('【QQYUN-4517】beforeEach');
-  //console.warn('from', from);
-  //console.warn('to', to);
-  //console.groupEnd();
+  let title = '默认标题'; // 默认标题
+  // 根据域名设置不同标题
+  if (window.location.hostname.includes('sohoeb2b')) {
+    title = '苏豪通';
+  } else {
+    title = 'AdWeb V3';
+  }
+
+  // 如果路由配置中有自定义标题,优先使用路由配置的标题
+  if (to.meta && to.meta.title) {
+    title = to.meta.title;
+  }
+
+  // 修改页面标题
+  document.title = title;
+
+  // 动态设置 Open Graph 标签
+  const setMetaTag = (property, content) => {
+    let meta = document.querySelector(`meta[property="${property}"]`);
+    if (!meta) {
+      meta = document.createElement('meta');
+      meta.setAttribute('property', property);
+      document.head.appendChild(meta);
+    }
+    meta.setAttribute('content', content);
+  };
+
+  setMetaTag('og:title', title);
+  setMetaTag('og:description', `${title}是一个强大的企业管理平台`);
+  setMetaTag('og:image', 'https://v3.sohoeb2b.com/logo.png');
+  setMetaTag('og:url', window.location.href);
   next();
 });
 

+ 0 - 1
src/router/routes/basic.ts

@@ -15,7 +15,6 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
   children: [
     {
       path: '/:path(.*)*',
-      name: PAGE_NOT_FOUND_NAME,
       component: EXCEPTION_COMPONENT,
       meta: {
         title: 'ErrorPage',