【发布时间】:2018-11-16 10:18:14
【问题描述】:
我正处于危机之中。我是 Angular 的新手,甚至是 Android Studio 的新手,并且已经拍摄了我所有的资源来试图解决这个问题,如果这是显而易见的事情,我很抱歉......
问题:为什么当我尝试通过 Android Studio 启动我的 Angular 应用程序时,会收到 404 错误。
说明: 目标是通过 android studio 将我的 angular web 应用程序包装在 webview 中,使其成为混合应用程序,从而将我的 angular web 应用程序启动到 playstore ......我正在关注这个 web 教程任务...
https://www.youtube.com/watch?v=a5dlmqM9Oo8
如果我测试像谷歌这样的网站地址,这可以工作,但如果我尝试我的 Angular 应用程序地址,屏幕保持空白或返回 404“在此服务器上找不到请求的 URL”。我已经在个人服务器上启动了我的 Angular 应用程序,它可以通过我的浏览器完美运行。
我的猜测是,角度路由会阻止 webview 加载应用程序...我已经尝试了以下修复,没有任何更改...
1) 哈希
How to use the HashLocationStrategy with the Auth0 Lock widget for user login
@NgModule({
imports: [RouterModule.forRoot(routes,{useHash: true})], ...
2) Apache 服务器中的 .htaccess
https://angular.io/guide/deployment#development-servers
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
如果您需要更多代码,请告诉我。我不确定这是否可能,但如果不是,我将不得不学习 Ionic 或找出其他东西。感谢stackoverflow
【问题讨论】:
标签: android angular android-studio