如何在 angularjs 中使用 ui.router 的 $stateChangeStart?
How to work with ui.router's $stateChangeStart in angularjs?
在我的 angularjs 移动应用程序中,我需要满足某些要求。最初,该应用程序位于主页中。如果用户需要转到该应用程序的下一页,他必须单击该特定内容。它会将他们重定向到该特定内容的下一页。之后,如果他想转到上一个(后退)页面,他必须单击后退按钮。
我需要的是,当用户返回他所在的上一页时,该页面正在重新加载。与其重新加载之前的页面,不如将他带到他之前所在的同一个地方。那么,如何禁用重新加载。我认为可以使用 'ui.router' 及其 $stateChangeStart 来实现。对于 url 路由,我使用“$routeProvider”。那么如何实现这一点呢?请帮帮我。
对于主页,url 是 -
'/myapp/landingpage'
对于下一页(当他单击特定内容时),url 是 -
'myapp/content/:contentId'
如果您的主页是普通静态页面 - 则不需要任何内容 - 主页模板已缓存在 $templateCache 中。
否则,如果您的主页有一些从某些服务获取的数据,我建议您将数据缓存在 angularjs 服务层本身。
您可以探索 $cacheFactory 了解更多详情。
如果你不想直接使用 $cacheFactory,你可以简单地在你的 $http.get 请求中使用 'cahce:true' 属性 :-
$http.get(url, { cache: true}).success(...);
来自$http docs:-
cache – {boolean|Cache} – If true, a default $http cache will be used
to cache the GET request, otherwise if a cache instance built with
$cacheFactory, this cache will be used for caching.
我们的想法是不要搞乱 view/states 缓存并将该责任转移到您的服务层。
在我的 angularjs 移动应用程序中,我需要满足某些要求。最初,该应用程序位于主页中。如果用户需要转到该应用程序的下一页,他必须单击该特定内容。它会将他们重定向到该特定内容的下一页。之后,如果他想转到上一个(后退)页面,他必须单击后退按钮。
我需要的是,当用户返回他所在的上一页时,该页面正在重新加载。与其重新加载之前的页面,不如将他带到他之前所在的同一个地方。那么,如何禁用重新加载。我认为可以使用 'ui.router' 及其 $stateChangeStart 来实现。对于 url 路由,我使用“$routeProvider”。那么如何实现这一点呢?请帮帮我。
对于主页,url 是 -
'/myapp/landingpage'
对于下一页(当他单击特定内容时),url 是 -
'myapp/content/:contentId'
如果您的主页是普通静态页面 - 则不需要任何内容 - 主页模板已缓存在 $templateCache 中。
否则,如果您的主页有一些从某些服务获取的数据,我建议您将数据缓存在 angularjs 服务层本身。
您可以探索 $cacheFactory 了解更多详情。
如果你不想直接使用 $cacheFactory,你可以简单地在你的 $http.get 请求中使用 'cahce:true' 属性 :-
$http.get(url, { cache: true}).success(...);
来自$http docs:-
cache – {boolean|Cache} – If true, a default $http cache will be used to cache the GET request, otherwise if a cache instance built with $cacheFactory, this cache will be used for caching.
我们的想法是不要搞乱 view/states 缓存并将该责任转移到您的服务层。