使用Ember在路由器中定义根路径

ale*_*ngn 3 javascript ember.js ember-router

我想知道是否可以将特定文件夹设置为我的路由/视图/模板/控制器的根路径?

例如,我的项目看起来像这样:

/controllers
  /base
  /main
    /index.js
    /welcome
      /index.js

/routes
  /base
  /main
    /index.js
    /welcome
      /index.js

/templates
  /main
    /index.hbs
    /welcome
      /index.hbs

/views
  /base
  /main
    /index.js
    /welcome
      /index.js
Run Code Online (Sandbox Code Playgroud)

我的main文件夹是我的所有控制器,路由,模板和视图的根文件夹.

使用网址:

  • mywebsite.com 将访问该页面 /main/index.js
  • mywebsite.com/welcome 将访问该页面 /main/welcome/index.js

谢谢

Kel*_*den 5

您可以通过为根路径提供空路径来完成此操作:

Router.map(function() {
  this.resource('main', { path: '' }, function() {
    this.resource('main.welcome', { path: 'welcome' }, function() {});
  });
});
Run Code Online (Sandbox Code Playgroud)

mywebsite.com给你main/index.jsmywebsite.com/welcome给你main/welcome/index.js.