我有一个基于路由的角度应用程序,我想要的是将它作为 html 文件捆绑到 WebView 应用程序中,以便它可以被访问~/app_path/index.html
我成功地构建了它ng build --prod --output-path ./../ng-build
并且它在浏览器中加载良好。
问题是如果我使用路由器模块,我会收到Unhandled Navigation Error
警告并且路由不起作用。
我尝试使用哈希 useHash
imports: [RouterModule.forRoot(routes, {useHash: true})],
并预计它可能适用于路线,例如
`~/app_path/index.html#settings`
`~/app_path/index.html#profile`
`~/app_path/index.html#details`
但这无济于事 - 路由器在应用程序启动后立即崩溃
在这种file://
模式下是否有任何解决方案或解决方法来实现路由?或者也许是在应用程序中使用的另一种架构方法,而不是路由。
根据此线程将<base>
href attr设置为绝对路径有助于解决路由问题
<script>document.write('<base href="' + document.location + '" />');</script>
所以基本元素看起来像这样
<base href="file:///Users/guest/build/index.html">
路由演示:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句