1. 程式人生 > >JS頁面跳轉的各種形式

JS頁面跳轉的各種形式

  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'}});