1

我正在使用铁路由器在流星框架中渲染模板,因为我可能遵循了一个过时的教程,在我看来,语法发生了变化,我无法弄清楚。

布局.html

<div class="container">
    <div class="row">
        <div class="span2">
            <p>cell</p>
        </div>
            <div class="span7">
                <p>cell</p>
            </div>
                <div class="span3">
                    <p>cell</p>
                </div>
    </div>
</div>

index.js

function.setDefault ('category', null );
Router.configure({
    layoutTemplate:'layout',
    yieldTemplates:{
        'products':{to:'products'},
        'cart':{to:'cart'},
        'categories':{to:'categories'}
    }
    });
Router.route(function(){

    this.route('/', layout);
    this.route('/products',{
        data:function(){
            Session.set('category',this.params.name);

    },
    template:'layout',
    path:'/:name'
    })
});

以下错误发生意外令牌(1:8)

4

1 回答 1

0

如果你有 Router.route 并在函数中使用 this.route,Router.route 应该读取 Router.map 但是不推荐使用 Router.route (没有地图包装器),如下所示:

Session.setDefault ('category', null );           

Router.configure({ 
    layoutTemplate:'layout', 
    yieldTemplates:{ 
        'products':{to:'products'}, 
        'cart':{to:'cart'}, 
        'categories':{to:'categories'} 
    } 
}); 
//You will need to declare a template at the least here so it knows what to render to main area
Router.route('/', {template: "template_name"); 
Router.route('/products/:name',{ 
    onBeforeAction:function(){ 
        Session.set('category',this.params.name); 
        this.next ();
    }, 
    //you don't need this to be layout
    //as you are defining a default layout above 
    //but you will need to specify a template for the main yield area
    template:'template_name'
    // you don't need to specify path here as it will use '/products'
    //if you want to specify a route name use line below
    //,name: 'routename'
});

网址在哪里/products/product_name

template_name您要在 main 中渲染的模板在哪里{{> yield}}

在您的布局模板中,您需要将以下内容放置在您想要显示它们的任何位置

{{> yield 'products'}}
{{> yield 'categories'}}
{{> yield 'cart'}}
{{> yield }} //this is the template you specify in template: 'template_name'

(通过我的手机完成,因此无法测试,但如果它不适合您,可以稍后更新)

于 2016-03-24T11:52:48.637 回答