JS页面跳转的各种形式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24147051/article/details/84562700
  1. 普通跳转页面

    const url = “/XXX/YYYYY/MMMMM”;
    window.location.href = url ;

  2. 普通跳转打开新页面

    const url = “/XXX/YYYYY/MMMMM”;
    window.open(url, “_blank”, “”);

  3. vue页面跳转

    // 字符串

    this.$router.push(’/home/first’)

    // 对象

    this.$router.push({ path: ‘/home/first’ })

    // 命名的路由(可以传递参数)

    this.$router.push({ name: ‘home’, params: { userId: wise }})

  4. react页面跳转

    第一种:this.props.router.push(path)

    第二种:this.context.router.push(path)

如果需要传递参数:

this.props.router.push({ pathname : '/', state : { msg : 'you have logined and will redirect to your page'}});  

this.context.router.push({ pathname : '/', state : { msg : 'you have logined and will redirect to your page'}});  

猜你喜欢

转载自blog.csdn.net/qq_24147051/article/details/84562700
今日推荐