我正在查看angularjs源代码并特别注意onUrlChange
方法:
self.onUrlChange = function(callback) {
// TODO(vojta): refactor to use node's syntax for events
if (!urlChangeInit) {
// We listen on both (hashchange/popstate) when available, as some browsers (e.g. Opera)
// don't fire popstate when user change the address bar and don't fire hashchange when url
// changed by push/replaceState
// html5 history api - popstate event
if ($sniffer.history) jqLite(window).on('jqLite(window).on('popstate', cacheStateAndFireUrlChange);', cacheStateAndFireUrlChange);
// hashchange event
jqLite(window).on('hashchange', cacheStateAndFireUrlChange);
urlChangeInit = true;
}
文档说:
当url从外部更改时调用回调 角:
- 用户在地址栏中输入不同的网址
如果用户在地址栏中键入不同的网址,我真的不明白如何触发回调cacheStateAndFireUrlChange
。如果用户这样做,浏览器将导航到不存在cacheStateAndFireUrlChange
功能的不同页面。我在这里缺少什么?