[英]How to create multiple independent pages in react without loading all components
This might be a stupid question.这可能是一个愚蠢的问题。 I searched for an answer and I all get is
router
solutions.我搜索了一个答案,我得到的都是
router
解决方案。 I have created a react SPA and I want to create a separate independent page for admin that does not get loaded along with the main app and vice versa.我创建了一个反应 SPA,我想为管理员创建一个单独的独立页面,该页面不会与主应用程序一起加载,反之亦然。 How can I do this?
我怎样才能做到这一点? If enter this in the url bar
http://localhost:3000/admin.html
, It still loads the main app no matter what.如果在 url 栏
http://localhost:3000/admin.html
中输入这个,无论如何它仍然会加载主应用程序。
you can still use router and load only the components needed using lazy
.您仍然可以使用 router 并仅使用
lazy
加载所需的组件。 From react website来自反应网站
import React, { Suspense, lazy } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
const Home = lazy(() => import('./routes/Home'));
const About = lazy(() => import('./routes/About'));
const App = () => (
<Router>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
</Switch>
</Suspense>
</Router>
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.