分包目录结构示例:
在app.json中添加subpackages字段,如下:
参照官方app.json配置实例及目录结构:
{
"pages": [
"page/tabBar/component/index",
"page/tabBar/API/index"
],
"window": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "演示",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [{
"pagePath": "page/tabBar/component/index",
"iconPath": "image/icon_component.png",
"selectedIconPath": "image/icon_component_HL.png",
"text": "组件"
}, {
"pagePath": "page/tabBar/API/index",
"iconPath": "image/icon_API.png",
"selectedIconPath": "image/icon_API_HL.png",
"text": "接口"
}]
},
"subPackages": [
{
"root": "page/component/",
"pages": [
"pages/view/view",
"pages/scroll-view/scroll-view",
"pages/swiper/swiper",
"pages/text/text",
"pages/icon/icon",
"pages/progress/progress",
"pages/button/button",
"pages/checkbox/checkbox",
"pages/form/form",
"pages/input/input",
"pages/label/label",
"pages/picker/picker",
"pages/radio/radio",
"pages/slider/slider",
"pages/switch/switch",
"pages/textarea/textarea",
"pages/navigator/navigator",
"pages/navigator/navigate",
"pages/navigator/redirect",
"pages/image/image",
"pages/audio/audio",
"pages/video/video",
"pages/map/map",
"pages/canvas/canvas"
]
},
{
"root": "page/API/",
"pages": [
"pages/login/login",
"pages/get-user-info/get-user-info",
"pages/request-payment/request-payment",
"pages/share/share",
"pages/share-button/share-button",
"pages/custom-message/custom-message",
"pages/template-message/template-message",
"pages/set-navigation-bar-title/set-navigation-bar-title",
"pages/navigation-bar-loading/navigation-bar-loading",
"pages/navigator/navigator",
"pages/pull-down-refresh/pull-down-refresh",
"pages/animation/animation",
"pages/action-sheet/action-sheet",
"pages/modal/modal",
"pages/toast/toast",
"pages/get-network-type/get-network-type",
"pages/on-network-status-change/on-network-status-change",
"pages/get-system-info/get-system-info",
"pages/on-compass-change/on-compass-change",
"pages/make-phone-call/make-phone-call",
"pages/scan-code/scan-code",
"pages/request/request",
"pages/web-socket/web-socket",
"pages/upload-file/upload-file",
"pages/download-file/download-file",
"pages/image/image",
"pages/voice/voice",
"pages/file/file",
"pages/on-accelerometer-change/on-accelerometer-change",
"pages/canvas/canvas",
"pages/background-audio/background-audio",
"pages/video/video",
"pages/get-location/get-location",
"pages/open-location/open-location",
"pages/choose-location/choose-location",
"pages/storage/storage"
]
}
],
"networkTimeout": {
"request": 10000,
"connectSocket": 10000,
"uploadFile": 10000,
"downloadFile": 10000
},
"debug": false
}
subpackages中的pages路径是相较于root字段的,
root字段相较于根目录
此后的路由跳转还是要写完全路径,比如我个人项目结构:
跳转写法:
tapToMember(){
wx.navigateTo({
url: "/pages/litePage/pages/member/member"
})
},
app.json配置:
官方文档中可以下载示例源码:[https://developers.weixin.qq.com/miniprogram/dev/framework/subpackages/basic.html]