Skip to content

页面配置

文件位置 src/pages.json,具体配置可文档 https://uniapp.dcloud.net.cn/collocation/pages.html

{
    "pages": [
        {
            "path": "pages/index/index",
            "style": {
                "navigationBarTitleText": "%pages.index.index%"
            }
        },
		{
            "path": "pages/user/set",
            "style": {
                "navigationBarTitleText": "%pages.user.set%"
            },
            "loginVerify": true // 登录验证
        },
        ...
    ],
    "subPackages": [],
    "globalStyle": {
        "navigationBarTextStyle": "black",
        "navigationBarTitleText": "",
        "navigationBarBackgroundColor": "#FFFFFF",
        "backgroundColor": "#F8F8F8"
    },
	"tabBar": {
        "color": "#666666",
        "selectedColor": "#333333",
        "backgroundColor": "#ffffff",
        "list": [
            {
                "pagePath": "pages/index/index"
            },
			...
        ]
	},
    "easycom": {
        "custom": {
			...
        }
    }
}

路由拦截

文件位置 src/utils/interceptor.ts

系统使用uni.addInterceptor进行路由拦截,拦截uni的uni.navigateTo、uni.redirectTo、uni.reLaunch、uni.switchTab等方法,统一进行登验证和权限控制等操作。

...
// 添加路由拦截器
const list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach((item) => {
	uni.addInterceptor(item, {
		invoke(e) {
			// 跳转页面登录验证
			...
		},
		fail(err) {
			// 失败回调拦截
			console.log(err);
		},
	});
});
...

Released under the Apache-2.0 License.