You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
preact-async-route provides <AsyncRoute> tag to load your components lazily.
<AsyncRoute> provides similar props to return a lazily loaded component either as a Promise resolving to the component or return the component in a callback.
<AsyncRoute> also has a loading props, to which you can pass a component to be shown while the component is being lazily loaded.
Version 2.0
Version 2.0 brings support for a new prop component
in order to make usage of already imported components now preact-async-route will support 2 props
component this will just take the JSX component itself and NOT the function
for function calls getComponent is the prop
check README 👇
Usage Example
import{h,render}from'preact';importRouter,from'preact-router';importAsyncRoutefrom'preact-async-route';importHomefrom'./Components/Home/Home.jsx';importTermsfrom'./Components/Terms/Terms.jsx';importLoadingfrom'./Components/Loading/Loading.jsx';/** @jsx h *//** arguments passed to getComponent: url -- matched url cb -- in case you are not returning a promise props -- props that component will recive upon being loaded */functiongetProfile(url,cb,props){returnimport('../component/Profile/Profile.jsx').then(module=>module.default);}constMain=()=>(<Router><Homepath="/"/><Termspath="/terms"/><AsyncRoutepath="/profile/:userid"component={Home}/><AsyncRoutepath="/friends/:userid"getComponent={getProfile}loading={()=>{return<Loading/>}}/></Router>);