运行 angular 7 基于路由的应用程序作为 `file://`(无服务器)
Run angular 7 routing-based app as `file://` (without server)
我有 angular 应用程序 基于路由 ,我想要的是将它作为 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://
模式下是否有任何解决方案或变通方法来实现路由?或者也许在此处的应用程序中使用另一种架构方法而不是路由。
根据this thread设置<base>
href attr 到绝对路径有助于解决路由问题
<script>document.write('<base href="' + document.location + '" />');</script>
因此基本元素将如下所示
<base href="file:///Users/guest/build/index.html">
路由演示:
我有 angular 应用程序 基于路由 ,我想要的是将它作为 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://
模式下是否有任何解决方案或变通方法来实现路由?或者也许在此处的应用程序中使用另一种架构方法而不是路由。
根据this thread设置<base>
href attr 到绝对路径有助于解决路由问题
<script>document.write('<base href="' + document.location + '" />');</script>
因此基本元素将如下所示
<base href="file:///Users/guest/build/index.html">
路由演示: