不扩展应用程序模板 emberjs

Not extending the application template emberjs

本文关键字:emberjs 应用程序 扩展      更新时间:2023-09-26
有什么

方法可以不扩展Emberjs中的应用程序模板吗?就像我有一条路线一样,出于 SEO 目的需要/questions url,但它的设计与所有其他页面完全不同。所以我不希望它继承应用程序模板。这可能吗?

我能想到你有两个选择。第一个是在评论中提出的:为questions和其他所有内容创建单独的顶级路由:

// templates/application.js
{{outlet}}
// templates/questions.js
{{! whatever you want for the questions template }}
// templates/base.js
{{! base template stuff, headers, nav bars, content, etc. }}
// router.js
Router.map({
    this.route('questions');
    this.resource('base', function() {
        this.route('base1');
        ....
    });
});
关于

这将导致/base/base1形式的路由的注释不正确。通过使用this.resource,路由的形式将是/base1

使用插座

还有另一种方法可以满足您的需求,也可能不能满足您的需求。它涉及在应用程序模板中放置一个自定义出口,该出口可能由子路由填充。然后为"常规路由"定义一个超类,该超类定义一个将标头物质呈现到该出口的renderTemplate

// templates/application.js
{{outlet name='header'}}
{{outlet name='main'}}
// mixins/normal-route.js
renderTemplate() {
    this.render('header', {
        outlet: 'header'
    });
}
// router.js
Router.map({
    this.route('questions');
    this.route('base1');
});
// pods/base1/route.js
export default NormalRoute.extend({...

这样做的好处是允许应用程序模板更具"可读性"和语义性,因为它显式显示它由(可能的(标头部分(填充了一些其他组件(和"主"部分组成。