import\s+React\s+from\s+'react';\nimport\s+{\s+BrowserRouter\s+as\s+Router,\s+Route,\s+Switch\s+}\s+from\s+'react-router-dom';\n\nconst\s+Home\s+=\s+React.lazy\s+(\s=>\s+import('./components/Home'));\nconst\s+About\s+=\s+React.lazy\s+(\s=>\s+import('./components/About'));\nconst\s+Contact\s+=\s+React.lazy\s+(\s=>\s+import('./components/Contact'));\n\nconst\s+App:\s+React.FC\s+=\s+()\s=>\s+{\n\s+return\s+(\n\s+\s+\n\s+\s+\s+<React.Suspense\s+fallback={

Loading...
}>\n\s+\s+\s+\s+\n\s+\s+\s+\s+\s+<Route\s+exact\s+path="/"\s+component={Home}\s+/>\n\s+\s+\s+\s+\s+<Route\s+path="/about"\s+component={About}\s+/>\n\s+\s+\s+\s+\s+<Route\s+path="/contact"\s+component={Contact}\s+/>\n\s+\s+\s+\s+\n\s+\s+\s+</React.Suspense>\n\s+\s+\n\s+);\n}\n\nexport\s+default\s+App;

React路由懒加载:使用TS和BrowserRouter实现组件按需加载

原文地址: http://www.cveoy.top/t/topic/qA9v 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录