路由
配置路由
在app.tsx入口文件的主组件中,
//pages中配置路由,第一个为首页
config: Config = {
pages: [
'pages/index/index',
'pages/test/test.tsx'
],
Taro.navigateTo(Object) 跳转,有历史记录
Taro.redirectTo(Object) 重定向,无历史记录
Taro.switchTab(Object)
pages/test/test.tsx:
import Taro,{Component,Config} from '@tarojs/taro'
import {View,Text,Button} from '@tarojs/components'
class Index extends Component{
handleClick = ()=>{
Taro.navigateTo({
url:'/pages/index/index?id=3'
})
}
render(){
return (
<View>
<Button onClick = {this.handleClick}>点击跳转</Button>
</View>
)
}
}
查询字符串的方式页面传参,在目标页面组件中componentWillMount(){}中this.$router.params.id接收