有关taro的路由的问题

1、我们在全局的文件中定义路由

  pages: ["pages/index/index", "pages/ceping/index1"],

2、我们在文件中使用这些路由

Taro.navigateTo({ url: "pages/ceping/index1" });

编译以后说会报错,因为会按照相对路径处理。

3、怎么办呢,我们这样改就行了。

Taro.navigateTo({ url: "/pages/ceping/index1" });

 网上说的这些貌似都不怎么好使,现在的社会人云亦云的人也太多。

1.配置

config/index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const path = require('path')
...
 
const config = {
  alias: {
    '@actions': path.resolve(__dirname, '..''src/actions'),
    '@assets': path.resolve(__dirname, '..''src/assets'),
    '@components': path.resolve(__dirname, '..''src/components'),
    '@constants': path.resolve(__dirname, '..''src/constants'),
    '@reducers': path.resolve(__dirname, '..''src/reducers'),
    '@styles': path.resolve(__dirname, '..''src/styles'),
    '@utils': path.resolve(__dirname, '..''src/utils')
  },
}

感谢京东公司,给予的最宝贵的职业经验。

原文地址:https://www.cnblogs.com/sexintercourse/p/13495061.html