浏览代码

fix: 跌由都改为 # hash 模式

王晓东 2 月之前
父节点
当前提交
98363d82ac
共有 5 个文件被更改,包括 18 次插入11 次删除
  1. 1 1
      build/assets/index-DiVtD1w9.js
  2. 1 1
      build/site.html
  3. 8 3
      src/App.tsx
  4. 6 4
      src/components/Header.tsx
  5. 2 2
      src/contexts/RouterContext.tsx

文件差异内容过多而无法显示
+ 1 - 1
build/assets/index-DiVtD1w9.js


+ 1 - 1
build/site.html

@@ -5,7 +5,7 @@
       <meta charset="UTF-8" />
       <meta name="viewport" content="width=device-width, initial-scale=1.0" />
       <title>Anycall App Landing Page</title>
-      <script type="module" crossorigin src="/fara/h5/assets/index-CIBPE-th.js"></script>
+      <script type="module" crossorigin src="/fara/h5/assets/index-DiVtD1w9.js"></script>
       <link rel="stylesheet" crossorigin href="/fara/h5/assets/index-1Br_J6GP.css">
     </head>
 

+ 8 - 3
src/App.tsx

@@ -14,8 +14,8 @@ import { FAQPage } from './components/pages/FAQPage';
 import { ContactPage } from './components/pages/ContactPage';
 
 function AppContent() {
-  const { currentPage } = useRouter();
-  
+  const { currentPage, navigateTo } = useRouter();
+  const _page = window.location.hash.split('#')?.[1] ?? currentPage
   // Ensure hash scrolling works even after page is fully loaded
   useEffect(() => {
     // Wait for all images and resources to load
@@ -38,9 +38,14 @@ function AppContent() {
       }
     }
   }, [currentPage]);
+
+  useEffect(()=> {
+    navigateTo(_page)
+  }, [])
   
   const renderPage = () => {
-    switch (currentPage) {
+    
+    switch (_page) {
       case 'home':
         return <Home />;
       case 'about':

+ 6 - 4
src/components/Header.tsx

@@ -17,10 +17,12 @@ export function Header() {
 
   const scrollToSection = (id: string) => {
     // Close mobile menu first for better UX
+    console.log(currentPage, id,3333)
     setMobileMenuOpen(false);
-    if (currentPage !== 'home') {
-      navigateTo('home', id);
-    } else {
+    navigateTo('home', id);
+    // if (currentPage !== 'home') {
+    //   navigateTo('home', id);
+    // } else {
       // Small delay to ensure mobile menu is closed
       setTimeout(() => {
         const element = document.getElementById(id);
@@ -29,7 +31,7 @@ export function Header() {
           window.history.pushState(null, '', `#${id}`);
         }
       }, 50);
-    }
+    // }
   };
 
   const handleNavigation = (page: 'faq' | 'contact') => {

+ 2 - 2
src/contexts/RouterContext.tsx

@@ -97,8 +97,8 @@ export function RouterProvider({ children }: { children: ReactNode }) {
     const url = hash ? `${path}#${hash}` : path;
     const BASE_PATH = VITE_BASE_PATH
     // Update browser URL without reloading
-    window.history.pushState({ page }, '', BASE_PATH + url);
-    
+    window.history.pushState(null, '', `#${page}`);
+    console.log(page, hash,3334)
     if (hash) {
       // If there's a hash, scroll to the section
       scrollToElement(hash, 150);

部分文件因为文件数量过多而无法显示