将流星的铁路由器参数传递给模板回调。

时间:2023-01-18 19:40:24

How do you pass the Iron Router parameters to a Template.myTemplate.rendered callback? The following route and callback function gives undefined for both console.log.

如何将铁路由器参数传递给模板。mytemplate ?显示回调?下面的路由和回调函数为console.log提供了未定义的。

URL

URL

http://localhost:3000/story/1234

Router.js

Router.js

Router.map( function() {

    this.route('story', {
        path: '/story/:_id',
        template: 'story'
    })

})

story.js

story.js

Template.story.rendered = function () {

    console.log('params: ', this.params)    // undefined
    console.log('_id: ', this._id)    // undefined

}

1 个解决方案

#1


25  

Have you tried Router.current().params?

你有试过Router.current().params吗?

#1


25  

Have you tried Router.current().params?

你有试过Router.current().params吗?