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

taro3.x h5自定义路由customRoutes,在页面相互跳转之间无效 #7409

Closed
meibin08 opened this issue Aug 21, 2020 · 2 comments
Closed
Assignees
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@meibin08
Copy link

相关平台

H5

浏览器版本: chrome 84
使用框架: React 、typescript

复现步骤

config/index.js h5部分配置如下:

h5: {
    output: {
      filename: 'js/[name].js',
      chunkFilename: 'js/[name].[chunkhash:8].js',
      // publicPath: '/assets/',
    },
    publicPath: '/',
    staticDirectory: 'static',
    esnextModules: ['taro-ui'],
    postcss: {
      autoprefixer: {
        enable: true,
        config: {},
      },
      cssModules: {
        enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
        config: {
          namingPattern: 'module', // 转换模式,取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
    miniCssExtractPluginOption: {
      filename: 'css/[name].[hash:8].css',
      chunkFilename: 'css/[name].[chunkhash:8].css',
    },
    imageUrlLoaderOption: {
      limit: false,
      esModule: false,
      name: 'images/[name].[hash:8].[ext]',
    },
    router: {
      mode: 'browser',
      customRoutes: {
        '/pages/index/index': '/home',
        '/pages/mine/index': '/personalcenter',
      },
    },
  },

服务启动后,步骤:

  • http://localhost:8080/home 正常打开,
  • 点击页面按钮跳转至 /personalcenter 页,Taro.redirectTo({url : '/pages/mine/index' }),
  • !!此时报错:Uncaught (in promise) Error: Route not found ,不会跳转成功
  • 直接在浏览器输入 http://localhost:8080/personalcenter ,正常

期望结果

Taro.redirectTo({url : '/pages/mine/index' }) 正常跳转打开,并浏览器显示为http://localhost:8080/personalcenter

实际结果

Uncaught (in promise) Error: Route not found

环境信息

Taro CLI 3.0.7 environment info:
    System:
      OS: macOS 10.14.5
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 12.16.1 - /usr/local/bin/node
      Yarn: 1.19.1 - /usr/local/bin/yarn
      npm: 6.13.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.7 => 3.0.7 
      @tarojs/mini-runner: 3.0.7 => 3.0.7 
      @tarojs/react: 3.0.7 => 3.0.7 
      @tarojs/runtime: 3.0.7 => 3.0.7 
      @tarojs/taro: 3.0.7 => 3.0.7 
      @tarojs/webpack-runner: 3.0.7 => 3.0.7 
      babel-preset-taro: 3.0.7 => 3.0.7 
      eslint-config-taro: 3.0.7 => 3.0.7 
      nervjs: ^1.5.7 => 1.5.7 
      react: 16.8.2 => 16.8.2 
      taro-ui: ^3.0.0-alpha.3 => 3.0.0-alpha.3 
    npmGlobalPackages:
      typescript: 3.1.1

补充官方文档说明:

image

@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Aug 21, 2020
@luckyadam luckyadam self-assigned this Aug 25, 2020
@luckyadam
Copy link
Member

升级至 3.0.8 试试

@meibin08
Copy link
Author

meibin08 commented Sep 1, 2020

升级至 3.0.8 试试

3.0.8可以了

@meibin08 meibin08 closed this as completed Sep 1, 2020
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
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
Archived in project
Development

No branches or pull requests

2 participants