angular - 为什么页面链接在 Cordova Angular 中不起作用?
问题描述
我有一个角度应用程序。我将该应用程序转换为 Cordova 中的 android 应用程序。主页正常工作,但角度路由链接不起作用。以下是我的 Cordova index.html 和路线链接
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="apple-touch-icon" sizes="76x76" href="assets/img/apple-
icon.png">
<link rel="icon" type="image/png" href="assets/img/favicon.png">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Now UI Kit Angular by Creative Tim</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0,
user-scalable=0, shrink-to-fit=no' name='viewport' />
<base href="./">
<!-- Fonts and icons -->
<link href="https://fonts.googleapis.com/css?
family=Montserrat:400,700,200" rel="stylesheet" />
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css"
rel="stylesheet">
</head>
<body class="sidebar-collapse">
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script><script
type="text/javascript" src="polyfills.js"></script><script
type="text/javascript" src="styles.js"></script><script
type="text/javascript" src="scripts.js"></script><script
type="text/javascript" src="vendor.js"></script><script
type="text/javascript" src="main.js"></script></body>
</html>
const routes: Routes =[
{ path: '', redirectTo: 'index', pathMatch: 'full' },
{ path: 'index', component: ComponentsComponent },
{ path: 'nucleoicons', component: NucleoiconsComponent },
{ path: 'examples/landing', component: LandingComponent },
{ path: 'examples/login', component: LoginComponent },
{ path: 'examples/profile', component: ProfileComponent },
{ path: 'odia', component: OdiaComponent }
];
解决方案
我认为问题与基本 href 中的“点”有关:
<base href="./">
因此,如果您检查它并删除一个点,它会起作用,但是加载静态文件会出现问题。
我遇到了类似的问题,并通过以下方式解决了它:
<base href="./">
从您的index.html文件中删除- 在您的主app.module.ts文件中添加下一个提供程序:
<your imports>
...
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
imports: [<your imports if are>...],
exports: [<your exports if are>...],
providers: [<your providers if are>...,
{
provide: APP_BASE_HREF,
useValue: '/'
}]
})
- 然后重建你的科尔多瓦项目。应该管用
推荐阅读
- sql - SQL 依赖关系查询 - SQL Server
- ios - 一个人的 Fastlane 会话在 CI 管道中工作,而另一个人却没有的常见原因是否有?
- php - 如何在 PHP 中使用 WCF 服务?
- javascript - 使用公共 ACM 在 AWS 上部署 Expressjs
- android - 使用 Mapbox SDK for Android 开始地理围栏的任何可能方式
- php - 在 Genesis Child Theme Wordpress 中创建全高移动菜单
- imap - 应该使用什么 url 来使用 libcurl 选择 imap 邮箱
- python - 使用 Pyplot 散布不透明度
- java - 错误:无法找到或加载主类 discord.java.bot.JavaDiscordBot
- javascript - VueJs - 如何在 v-if 中使用变量?