【taro react】---- h5路由配置取消路由上的#

68 阅读1分钟

默认打包访问路由

https://{{domain}}/#/pages/index/index

期望打包访问路由

https://{{domain}}/pages/index/index

解决文档

taro 路由相关的配置 h5.router

配置路由模式

配置路由模式。'hash' 与 'browser' 分别对应 hash 路由模式和浏览器 history 路由模式。默认值:'hash'。

实例

module.exports = {
  // ...
  h5: {
    // ...
    router: {
      mode: 'hash' // 或者是 'browser'
    }
  }
}

针对上面的配置,调用 Taro.navigateTo({ url: '/pages/index/index' }) 后,浏览器地址栏将被变为:

  1. https://{{domain}}/#/pages/index/index(hash 模式)
  2. https://{{domain}}/pages/index/index(browser 模式)