目录

替换历史记录条目(Replacing History Entries)

您可以使用link-to帮助程序在路径之间移动时向浏览器的历史记录添加条目,并使用replace=true选项替换当前条目。

语法 (Syntax)

{{#link-to 'link-text' 'route-name' replace = true}}
   //text here
{{/link-to}}

例子 (Example)

该示例显示如何替换浏览器历史记录中的当前条目。 创建名称为info的路由,并打开router.js文件以定义URL映射 -

import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend ({
   location: config.locationType,
   rootURL: config.rootURL
});
Router.map(function() {
   this.route('info');
});
export default Router;

使用以下代码打开在app/templates/下创建的application.hbs文件 -

//put the replace = true option to replace the browser history entries
{{link-to 'Click For Fruits List' 'info' replace = true}}
{{outlet}}

当您单击“Click For Fruits List”链接时,页面应打开info.hbs文件,其中包含以下代码 -

<ul>
   <li>Orange</li>
   <li>Banana</li>
</ul>
{{outlet}}

输出 (Output)

运行ember服务器; 你会收到以下输出 -

Ember.js模板替换历史记录

当您单击Click For Fruits List ,它将显示模板文件中的以下文本 -

Ember.js模板替换历史记录
↑回到顶部↑
WIKI教程 @2018