Angular 为什么页面链接在Cordova中不起作用?

Angular 为什么页面链接在Cordova中不起作用?,angular,cordova,Angular,Cordova,我有一个角度的应用程序。我将该应用程序转换为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- i

我有一个角度的应用程序。我将该应用程序转换为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 }
];

现在由创意蒂姆设计
常量路线:路线=[
{路径:'',重定向到:'index',路径匹配:'full'},
{path:'index',component:ComponentsComponent},
{路径:“核子图标”,组件:核子图标组件},
{path:'examples/landing',component:LandingComponent},
{path:'examples/login',component:LoginComponent},
{path:'examples/profile',component:ProfileComponent},
{路径:'odia',组件:OdiaComponent}
];

我认为问题与base href中的“点”有关:

<base href="./">

因此,如果您检查它并删除一个点,它将正常工作,但加载静态文件时会出现问题

我遇到了一个类似的问题,并用另一种方法解决了它:

  • index.html文件中删除
  • 在主app.module.ts文件中添加下一个提供者:
  • 
    ...
    从“@angular/common”导入{APP_BASE_HREF};
    @NGD模块({
    进口:[……],
    出口:[……],
    提供者:[……]。。。,
    {
    提供:APP_BASE_HREF,
    useValue:“/”
    }]
    })
    
  • 然后重建您的cordova项目。应该有用

  • 请详细说明,您是如何尝试导航的?它使用routerLink吗?
    <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: '/'
                  }]
    })