引入路由模块时的一个报错
No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.
解决办法
<head>
<!-- 加上这个标签 -->
<base href="/">
...
</head>
原因分析
"The tells the Angular router what is the static part of the URL. The router then only modifies the remaining part of the URL"
大概意思:angular路由对象需这么一个标签,来告诉它url的静态部分,即到时候不需要修改的部分。 而剩下的路由去修改。
本文解决了一个常见的Angular开发问题,即如何正确配置路由模块以避免‘Nobasehrefset’错误。通过在HTML头部添加<base href=/>标签,可以明确告知Angular路由器URL的静态部分,从而实现动态路由的正确解析。

被折叠的 条评论
为什么被折叠?



