Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5 taro router 重定向导致 页面栈丢失 #15994

Open
metaPigeon opened this issue Jun 28, 2024 · 0 comments
Open

H5 taro router 重定向导致 页面栈丢失 #15994

metaPigeon opened this issue Jun 28, 2024 · 0 comments
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@metaPigeon
Copy link

相关平台

H5

浏览器版本: Chrome 最新
使用框架: React

复现步骤

假设 页面栈 是如下:

const stacks = ['pageA', 'pageB', 'pageC', 'pageD', 'pageB']
Taro.redirectTo({
     url: pageB
})

这时页面会丢失栈,stacks 变成 ['pageA', 'pageB']

期望结果

重定向跳转页面不丢失栈

实际结果

重定向跳转页面丢失栈

环境信息

  Taro CLI 3.6.28 environment info:
    System:
      OS: macOS 14.4
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
      Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.2/bin/yarn
      npm: 10.5.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.28 => 3.6.28 
      @tarojs/components: 3.6.28 => 3.6.28 
      @tarojs/helper: 3.6.28 => 3.6.28 
      @tarojs/plugin-framework-react: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-alipay: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-h5: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-jd: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-qq: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-swan: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-tt: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-weapp: 3.6.28 => 3.6.28 
      @tarojs/react: 3.6.28 => 3.6.28 
      @tarojs/router: ^3.6.28 => 3.6.28 
      @tarojs/runtime: 3.6.28 => 3.6.28 
      @tarojs/shared: 3.6.28 => 3.6.28 
      @tarojs/taro: 3.6.28 => 3.6.28 
      @tarojs/taro-loader: 3.6.28 => 3.6.28 
      @tarojs/webpack5-runner: 3.6.28 => 3.6.28 
      babel-preset-taro: 3.6.28 => 3.6.28 
      eslint-config-taro: 3.6.28 => 3.6.28 
      react: ^18.0.0 => 18.3.1

补充信息

看了源码是下面问题导致:
packages/taro-router/src/router/stack.ts

  // 获取最近页面index 是从1 开始遍历,
  getLastIndex (pathname: string, stateWith = 1) {
    const list = [...this.stacks].reverse()
    return list.findIndex((page, i) => i >= stateWith && page.path?.replace(/\?.*/g, '') === pathname)
  }

请教为什么从1 开始,改成0 就没这个问题

@metaPigeon metaPigeon changed the title taro router 重定向导致 页面栈丢失 H5 taro router 重定向导致 页面栈丢失 Jun 28, 2024
@TheKonka TheKonka added V-3 Version - 3.x F-react Framework - React T-h5 Target - 编译到 H5 labels Jun 28, 2024
This was referenced Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Status: Padding
Development

No branches or pull requests

2 participants