简体   繁体   中英

routing in canjs not working as links are not getting an href value

I am new to canjs and following the tutorials on canjs site. I am using webpack to create a sample canjs page.

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: {
    }
});

When I see in the page, it's not routing to the home. Infact href value is not coming in output like below.

<a href="">Home</a>

console shows the following warning

MyAppView:3: Unable to find key "routeUrl()".

Like Justin mentioned, I think webpack is tree-shaking stacheRouteHelpers out of the build.

I think you can work around the issue by doing the following:

import { Component, stache, stacheRouteHelpers } from "can";

stache.addHelper(stacheRouteHelpers);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM