移动端打开页面其实是栈的入栈操作,关闭页面是栈的出栈操作,而传统的h5路由,如react-router是不具备栈这个特性的,满足不了移动端的需求
栈路由什么意思尼,其实app就是一个栈,栈遵循先进后出的原则,打开页面即入栈操作,关闭页面即出栈操作。
这里用的第三方的 @ionic/react-router 路由
import React, { useEffect } from 'react'
import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react'
import { IonReactHashRouter } from '@ionic/react-router'
import { Route, Redirect } from 'react-router-dom'
import loadable from '@loadable/component'
const MainTabs = loadable(() => import('@pages/main' /* webpackChunkName: 'MainTabs', webpackPrefetch: true */))
const ImgList = loadable(() => import('@pages/imgList' /* webpackChunkName: 'ImgList', webpackPrefetch: true */))
const ImgDetail = loadable(() => import('@pages/imgDetail' /* webpackChunkName: 'ImgDetail', webpackPrefetch: true */))
const App = () => {
useEffect(() => {
setupIonicReact({
mode: 'ios'
})
}, [])
return (
<IonApp>
<IonReactHashRouter>
<IonRouterOutlet>
<Route exact={true} path="/" render={() => <Redirect to="/main" />} />
<Route path={'/main'} exact component={MainTabs} />
<Route path={'/imgList'} exact component={ImgList} />
<Route path={'/imgDetail'} exact component={ImgDetail} />
</IonRouterOutlet>
</IonReactHashRouter>
</IonApp>
)
}
export default App