@heathenjs/taro-router-plugin
v1.1.5
Published
在Taro构建时自动生成路由方法及页面路由配置
Maintainers
Readme
@heathenjs/taro-router-plugin
在Taro构建时自动生成 @heathenjs/taro-router 所需的路由,并自动配置路由信息到app.config
特性
使用
Step 1
安装
pnpm
pnpm add @heathenjs/taro-router-plugin --save-dev
pnpm add @heathenjs/taro-routeryarn
yarn add @heathenjs/taro-router-plugin --dev
yarn add @heathenjs/taro-routernpm
npm install @heathenjs/taro-router-plugin --save-dev
npm install @heathenjs/taro-router --saveStep 2
在项目根目录创建配置文件 router.config.json ,参考配置信息如下:
{
"ignore": [
"components",
],
"defaultPage": "pages/default/index/index",
"packages": [
{
"name": "package1",
"pagePath": "./src/pages/package1"
},
{
"name": "package2",
"pagePath": "./src/pages/package2"
},
{
"name": "default",
"pagePath": "./src/pages/default",
"isMainPackage": true
}
]
}详见配置参数说明
Step 3
taro构建配置中增加插件
export default {
plugins: [
'@heathenjs/taro-router-plugin',
],
}完成!此时你不需要在 app.config 中再编写任何路由/页面相关的配置,插件会自动生成。
配置参数说明
ignore
不参与路由构建的目录,例如在页面中临时使用的一些组件。配置语法参考ignore
默认情况下,会将 pagePath 目录下所有
index.js/index.jsx/index.jsx/index.tsx识别为页面文件
defaultPage
进入小程序时的初始页面。必须是主包的页面。
packages
分包配置
name
分包名
pagePath
包页面路径
isMainPackage
是否为主包。必须有且仅有一个 package 的 isMainPackage 为true
