它有点奇怪的问题,但我不知道发生了什么。当我单击后面的浏览器按钮时,页面会发生变化,但URL
保持不变。当我再次单击后退按钮时,URL
会更改,但页面保持不变。
使用
后修复了这个问题window.history.pushState({},'',url);
但有了这个......问题是如果我一直点击后退按钮,我会循环2页。
示例: -
A -> B -> C -> (back) -> B -> (back) -> C -> (back) -> B -> (back) -> C-> (back) -> B -> (back)
注意: - 我在根路由模块中有RouterModule.forRoot(),在子路由中有RouterModule.forChild()。
我正在使用angular universal。
可能出现什么问题?怎么解决这个问题?
----------------------------------- XXXXXX ----------- ------------------------------------
更新
Was playing with code and i ran into Location of @angular/common.
This is great with popstate (resolved the url change issue) but the problem now is...
whenever i hit back button...it pop same page twice....
示例: -
A -> B -> C -> (back) -> B -> (back) -> B -> (back) -> A -> (back) -> A
----------------------------------- XXXXXX ----------- ------------------------------------
更新2: -
when using location.. i checked the history length...
the history length is not changing when the back button is clicked first time...
示例: -
A : length = 1 -> B : length = 2 -> C : length = 3 -> (back) -> B : length = 3 -> (back) ->
B : length = 2 -> (back) -> A : length = 2 -> (back) -> A : length = 1
P.S。 - >在询问库版本之前检查链接。
答案 0 :(得分:1)
检查文件
APP-routing.module.ts
并确保导入的路线类似于
RouterModule.forChild([])
而不是
RouterModule.forRoot([])
它将解决问题。