File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,9 +2,8 @@ import PageLayout from '@/layout';
22import { routes } from '@/routes' ;
33// import loadable from '@loadable/component';
44import { Toaster } from "@/components/ui/sonner" ;
5- import initMSW from '@/mock' ;
65import { useLocaleStore } from "@/store/index" ;
7- import { lazy , useEffect } from 'react' ;
6+ import { lazy } from 'react' ;
87import { IntlProvider } from 'react-intl' ;
98import {
109 BrowserRouter ,
@@ -24,25 +23,8 @@ const getLazyComponent = (path: string) => {
2423} ;
2524const isHashRouter = import . meta. env . VITE_ROUTE === 'hashRouter' ;
2625const Router = isHashRouter ? HashRouter : BrowserRouter ;
27- const mockEnable = ( import . meta. env . VITE_MOCK_ENABLE || 'true' ) == 'true' ;
2826export default function Index ( ) {
2927 const { locale, messages } = useLocaleStore ( ) ;
30- useEffect ( ( ) => {
31- if ( mockEnable ) {
32- initMSW ( ) ;
33- // 页面从后台恢复时,确保 SW 激活
34- const handleVisibilityChange = ( ) => {
35- if ( document . visibilityState === 'visible' ) {
36- initMSW ( ) ;
37- }
38- } ;
39-
40- document . addEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
41- return ( ) => {
42- document . removeEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
43- } ;
44- }
45- } , [ ] ) ;
4628 //路由组件懒加载
4729 return (
4830 < IntlProvider locale = { locale } messages = { messages } >
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ import './index.css';
66const mockEnable = ( import . meta. env . VITE_MOCK_ENABLE || 'true' ) == 'true' ;
77if ( mockEnable ) {
88 initMSW ( ) ;
9+ const handleVisibilityChange = ( ) => {
10+ if ( document . visibilityState === 'visible' ) {
11+ initMSW ( ) ;
12+ }
13+ } ;
14+ document . addEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
915}
1016createRoot ( document . getElementById ( 'root' ) ! ) . render (
1117 < StrictMode >
You can’t perform that action at this time.
0 commit comments