新建一个页面
知道现在已经有了一个默认的index,现在想做的是跳转到test这个文件
在路径 /src/app.tsx 下我们需要添加一个页面这样就将test,添加进了页面管理
config: Config = {
pages: [
'pages/index/index',
'pages/test/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black'
}
}
介绍带参路由,不带参的一样
在页面index中写一个点击事件
<Button onClick={this.toTest}>test</Button>
写一个方法
toTest(){
// 传入参数 id=2&type=test
Taro.navigateTo({
url: '/pages/page/test/index?id=2&type=test'
})
}
这样就调转了,在test的生命周期中即可,获得传来的参数
componentWillMount () {
console.log(this.$router.params) // 输出 { id: 2, type: 'test' }
}