簡體   English   中英

EmberJs中路由和路徑有什么區別

[英]What is the difference between route and path in EmberJs

EmberJs中路由和路徑有什么區別

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

route 的第一個參數是route的名稱。 它用於找到正確的文件來加載app/routes/about.js並提供鏈接<LinkTo @route="about">About</LinkTo> 如果您提供path選項,它將用於創建您在瀏覽器的地址欄中看到的 URL。

來自余燼指南

如果路徑與路由名稱相同,則可以省略該路徑。

對於您的情況,以下是等效的:

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

將導致 Ember 知道如何加載https://yoursite.com/abouthttps://yoursite.com/getting-in-touch的 URL

對於<LinkTo @route="contact">Contact Us</LinkTo>創建與 HTML 的鏈接,例如<a href="https://yoursite.com/getting-in-touch">Contact Us</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM