Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ember.js中非资源路由的通用继承布局_Javascript_Templates_Ember.js_Routes - Fatal编程技术网

Javascript Ember.js中非资源路由的通用继承布局

Javascript Ember.js中非资源路由的通用继承布局,javascript,templates,ember.js,routes,Javascript,Templates,Ember.js,Routes,我的应用程序的某些部分共享一个共同的布局。这些是非资源URL,如: /about /signup ... and more 我正在尝试在这些路由之间共享一个与我的主应用程序模板不同的基础模板。大多数应用程序都在/products下运行,因此products.hbs模板作为基础模板 我有工作。。。我只是不确定它是否遵循余烬公约,或者这是否是解决它的最佳方法。基本上,我有一个空的应用程序模板(只是一个出口),然后是一个要继承的自定义路由(routes/public route.js),用于加载共享

我的应用程序的某些部分共享一个共同的布局。这些是非资源URL,如:

/about
/signup
... and more
我正在尝试在这些路由之间共享一个与我的主应用程序模板不同的基础模板。大多数应用程序都在
/products
下运行,因此
products.hbs
模板作为基础模板

我有工作。。。我只是不确定它是否遵循余烬公约,或者这是否是解决它的最佳方法。基本上,我有一个空的应用程序模板(只是一个出口),然后是一个要继承的自定义路由(
routes/public route.js
),用于加载共享模板

以下是我所拥有的:

模板/应用程序.hbs

{{outlet}}
// this is the shared base template for routes not under `/products`
<div class="public">
  <h1>Share base template</h1>
  {{#link-to 'signup'}}Signup{{/link-to}}
  {{#link-to 'about'}}About{{/link-to}}
  {{outlet}}
</div>
<div class="splitview">
  <h1>Default app view</h1>
  {{#link-to 'products'}}Products{{/link-to}}
  {{#link-to 'products.featured'}}Featured{{/link-to}}
  {{outlet}}
</div
App.PublicRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render('layout/public');
    this.render({ into: 'layout/public' });
  }
});
App.AboutRoute = PublicRoute.extend();
App.SignupRoute = PublicRoute.extend();
App.Router = Ember.Router.extend();
App.Router.map(function() {
  this.resource('products', function() {
    this.resource('featured', { path: '/featured' }, function() {});
  });
  this.route('about');
  this.route('signup');
});
模板/layout/public.hbs

{{outlet}}
// this is the shared base template for routes not under `/products`
<div class="public">
  <h1>Share base template</h1>
  {{#link-to 'signup'}}Signup{{/link-to}}
  {{#link-to 'about'}}About{{/link-to}}
  {{outlet}}
</div>
<div class="splitview">
  <h1>Default app view</h1>
  {{#link-to 'products'}}Products{{/link-to}}
  {{#link-to 'products.featured'}}Featured{{/link-to}}
  {{outlet}}
</div
App.PublicRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render('layout/public');
    this.render({ into: 'layout/public' });
  }
});
App.AboutRoute = PublicRoute.extend();
App.SignupRoute = PublicRoute.extend();
App.Router = Ember.Router.extend();
App.Router.map(function() {
  this.resource('products', function() {
    this.resource('featured', { path: '/featured' }, function() {});
  });
  this.route('about');
  this.route('signup');
});
路由/about.js

{{outlet}}
// this is the shared base template for routes not under `/products`
<div class="public">
  <h1>Share base template</h1>
  {{#link-to 'signup'}}Signup{{/link-to}}
  {{#link-to 'about'}}About{{/link-to}}
  {{outlet}}
</div>
<div class="splitview">
  <h1>Default app view</h1>
  {{#link-to 'products'}}Products{{/link-to}}
  {{#link-to 'products.featured'}}Featured{{/link-to}}
  {{outlet}}
</div
App.PublicRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render('layout/public');
    this.render({ into: 'layout/public' });
  }
});
App.AboutRoute = PublicRoute.extend();
App.SignupRoute = PublicRoute.extend();
App.Router = Ember.Router.extend();
App.Router.map(function() {
  this.resource('products', function() {
    this.resource('featured', { path: '/featured' }, function() {});
  });
  this.route('about');
  this.route('signup');
});
routes/signup.js

{{outlet}}
// this is the shared base template for routes not under `/products`
<div class="public">
  <h1>Share base template</h1>
  {{#link-to 'signup'}}Signup{{/link-to}}
  {{#link-to 'about'}}About{{/link-to}}
  {{outlet}}
</div>
<div class="splitview">
  <h1>Default app view</h1>
  {{#link-to 'products'}}Products{{/link-to}}
  {{#link-to 'products.featured'}}Featured{{/link-to}}
  {{outlet}}
</div
App.PublicRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render('layout/public');
    this.render({ into: 'layout/public' });
  }
});
App.AboutRoute = PublicRoute.extend();
App.SignupRoute = PublicRoute.extend();
App.Router = Ember.Router.extend();
App.Router.map(function() {
  this.resource('products', function() {
    this.resource('featured', { path: '/featured' }, function() {});
  });
  this.route('about');
  this.route('signup');
});
router.js

{{outlet}}
// this is the shared base template for routes not under `/products`
<div class="public">
  <h1>Share base template</h1>
  {{#link-to 'signup'}}Signup{{/link-to}}
  {{#link-to 'about'}}About{{/link-to}}
  {{outlet}}
</div>
<div class="splitview">
  <h1>Default app view</h1>
  {{#link-to 'products'}}Products{{/link-to}}
  {{#link-to 'products.featured'}}Featured{{/link-to}}
  {{outlet}}
</div
App.PublicRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render('layout/public');
    this.render({ into: 'layout/public' });
  }
});
App.AboutRoute = PublicRoute.extend();
App.SignupRoute = PublicRoute.extend();
App.Router = Ember.Router.extend();
App.Router.map(function() {
  this.resource('products', function() {
    this.resource('featured', { path: '/featured' }, function() {});
  });
  this.route('about');
  this.route('signup');
});
这似乎奏效了。我可以转换到
signup
about
,它们的模板在
layout/public.hbs
出口中呈现。将你的
应用程序.hbs
仅仅作为一个出口是一种不好的做法吗?有更好的方法吗?这似乎是一种常见的情况