use
Fragment means that the placeholder component does not generate a tag. It helps solve the error problem and nothing else will be generated.
<Fragment><Fragment> <></>
The difference between the two is that Fragment can receive parameters. The key can be used to loop through the <> and cannot contain any parameters.
effect
You don't have to have a real DOM root tag
Case
import React, { Component, Fragment } from 'react'; // Fragment means that the placeholder component does not generate a label. It helps solve the error problem and nothing else will be generated.class Text extends Component { render() { return ( <Fragment> <input/> <ul> <li>Learn More</li> <li>Learn React</li> </ul> </Fragment> ); } } export default Text;
lazyLoad for routing components
//1. Dynamically load the routing component through React's lazy function and import() function ===> The routing component code will be packaged separatelyconst Login = lazy(()=>import('@/pages/Login')) //2. Specify using <Suspense> to display a custom loading interface before loading the route packaged file.<Suspense fallback={<h1>loading.....</h1>}> <Switch> <Route path="/xxx" component={Xxxx}/> <Redirect to="/login"/> </Switch> </Suspense>
Case
import React, { Component,lazy,Suspense } from 'react' import { NavLink,Route } from 'react-router-dom' // import Home from './Home' // import About from './About' import Loading from './Loading' const About = lazy(() => import("./About")) const Home = lazy(() => import("./Home")) export default class Demo extends Component { render() { return ( <div> <div className="row"> </div> <div className="row"> <div className="col-xs-2 col-xs-offset-2"> <div className="list-group"> <NavLink activeClassName="atguigu" className="list-group-item" to="/about">About</NavLink> <NavLink activeClassName="atguigu" className="list-group-item" to="/home">Home</NavLink> </div> </div> <div className="col-xs-6"> <div className="panel"> <div className="panel-body"> <Suspense fallback={<Loading/>}> {/* Register a route */} <Route path="/about" component={About} /> <Route path="/home" component={Home} /> </Suspense> </div> </div> </div> </div> </div> ) } }
The above is the detailed content of the lazyLoad case of the Fragment placeholder component not generating labels and routing components. For more information about the Fragment placeholder component, please follow my other related articles!