前言
使用Taro开发小程序,实现页面跳转时,出现eslint错误
1、代码
代码如下(示例):
Taro.redirectTo({ url: `/${String(PageUrls.MyRefounded)}` });
出现错误: error Invalid type of template literal expression @typescript-eslint/restrict-template-expressions
2、原因
eslint无法识别跳转URL的类型,应保证其为string类型。
3、解决办法
目前我想到想种解决办法,欢迎大家补充:
1、改变跳转路径书写方式
Taro.redirectTo({ url: ‘/’ + PageUrls.MyRefounded });
2、把路径强制转换成Strin类型
Taro.redirectTo({ url: `/${String(PageUrls.MyRefounded)}` });