gpt4 book ai didi

ember.js - EmberJS : how to know if route was called because the user clicked the Back button

转载 作者:行者123 更新时间:2023-12-02 03:34:48 26 4
gpt4 key购买 nike

我需要知道我的路线是否因为用户单击浏览器后退按钮而不是单击 {{link-to}} 链接而被调用。这样做的原因是因为我有一个可过滤列表,该列表在该路由的关联模板上有分页。如果用户离开此列表然后单击后退按钮,我的设计师希望过滤器的状态保持不变。但是,如果用户单击链接到达此列表,我的设计师希望重置过滤器和分页。

例子:

1) Users clicks the 'Books' navigation link and arrives at '/books'.
2) User filters the list goes to page 2 of results. This does not update the URL and user is still at '/books'.
3) User clicks one of the Books and goes to '/books/123'.
4) User clicks the browser Back button and goes back to '/books'. I need to show the filtered list at page 2.
5) User clicks the 'About Us' link and goes to '/about'
6) User clicks the 'Books' navigation link and arrives at '/books'. But this time, the user didn't click the browser Back button to arrive here, so I need to reset the filters and show a list of unfiltered Books on page 1.

在第 4 步和第 6 步中,用户到达“/books”和 BooksRoute,但他们到达那里的机制不同,因此我需要显示不同的书籍列表结果。有没有办法判断是否因为单击“后退”按钮而不是单击超链接而调用了路由?

最佳答案

如果不在 url 中保存状态,我可能会创建一个虚拟路由,在通过该链接访问时消除 books 状态。 (我假设 Controller 是您跟踪此状态的地方)。

路由器

this.resource('books', function(){
this.route('all');
});

路线

App.BooksAllRoute = Em.Route.extend({
setupController: function(){
var booksController = this.controllerFor('books');
booksController.set('filters', {});
// replaceWith replaces the history instead of adding additional history
// this may not be necessary since we're doing it mid transition
// this.transitionTo may be more appropriate
this.replaceWith('books');
}
});

模板

{{link-to 'Books' 'books.all'}}

您可能需要将虚拟路由移动到路由器中的相同级别,以避免已经填充书籍模型。 (我猜你实际上是如何过滤结果的)

关于ember.js - EmberJS : how to know if route was called because the user clicked the Back button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24295836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com