routing - canjs中的路由不起作用,因为链接没有获得href值
问题描述
我是 canjs 的新手,并按照 canjs 网站上的教程进行操作。我正在使用 webpack 创建一个示例 canjs 页面。
import { Component, stacheRouteHelpers } from "can";
Component.extend({
tag: "my-app",
view: `
<a href="{{ routeUrl(page='home') }}">Home</a>
<a href="{{ routeUrl(page='tasks') }}">Tasks</a>
`,
ViewModel: {
}
});
当我在页面中看到时,它没有路由到家。Infact href 值不会像下面那样出现在输出中。
<a href="">Home</a>
控制台显示以下警告
MyAppView:3: Unable to find key "routeUrl()".
解决方案
就像 Justin 提到的那样,我认为 webpack 是stacheRouteHelpers
在构建中摇树的。
我认为您可以通过执行以下操作来解决此问题:
import { Component, stache, stacheRouteHelpers } from "can";
stache.addHelper(stacheRouteHelpers);
推荐阅读
- c++ - 命名空间“火炬”中没有名为“KInt16”的成员
- javascript - sox 在节点 js 中以错误代码 1 退出
- android - 使用相机拍照后,黑屏几秒钟(2或3秒)
- python - 从 Pandas 数据框单元格内的字符串制作字典
- java - 如何访问超出类范围的变量?
- r - 如何在 R 中可视化这些数据澄清并识别模式?
- ssl-certificate - 证书和 Redhat Openshift
- git - 当它说“一切都是最新的”时,我如何强制 Git 删除远程文件?
- python - Motor 不会返回集合中的所有文档。怎么修?
- c - 如何整合这些几乎相同的 C 函数?