当我刷新页面时 angular4 css / js 不同

angular4 css / js differs when I refresh the page

当我用这种脚本加载页面时:

this.router.navigateByUrl('/report-result/'+report.id);

好像css都没有加载,js也是。 例如,我的 bootstrap 弹出窗口未加载,某些字段放错了位置。 当我直接使用 url 加载页面或刷新页面时,一切都很好。 你有想法吗?

您应该将导航方式更改为如下所示:

this.router.navigate(['report-result', report.id]);

记住路由是绝对的,所以如果您尝试访问 localhost/parentRoute/report-result/report。你必须这样做:

this.router.navigate(['parentRoute', 'report-result', report.id]);

或者像这样让它相对于 parentRoute:

this.router.navigate(['report-result', report.id], {relativeTo:'/parentReport'});