EmberJs中的路由和路径有什么区别

lei*_*lei 1 ember.js

EmberJs中的路由和路径有什么区别

Router.map(function () {
  this.route('about');
  this.route('contact', { path: '/getting-in-touch' });
});
Run Code Online (Sandbox Code Playgroud)

jrj*_*son 5

第一个参数route是路线的名称。它用于查找要加载的正确文件app/routes/about.js并提供链接<LinkTo @route="about">About</LinkTo>。如果您提供一个path选项,它将用于创建您在浏览器地址栏中看到的 URL。

来自ember 指南

如果路径与路由名称相同,则可以省略该路径。

对于您的情况,以下内容是等效的:

Router.map(function () {
  this.route('about', { path: '/about' });
  this.route('contact', { path: '/getting-in-touch' });
});
Run Code Online (Sandbox Code Playgroud)
Router.map(function () {
  this.route('about');
  this.route('contact', { path: '/getting-in-touch' });
});
Run Code Online (Sandbox Code Playgroud)

将导致 Ember 知道如何加载https://yoursite.com/about和 的URLhttps://yoursite.com/getting-in-touch

<LinkTo @route="contact">Contact Us</LinkTo>用 HTML 创建链接,例如<a href="https://yoursite.com/getting-in-touch">Contact Us</a>