繁体   English   中英

从静态页面/ URL进行角度路由

[英]angular routing from static page / URL

Angular 5(修订版)

经过一晚上的阅读和测试并尝试了不同的方法之后,我已经提炼了我的问题。

问题变成了,如何从应用程序外导航到我的角度应用程序中的路径。

我得到相同的结果-键入并通过href链接到除应用程序根目录以外的任何其他路径,会导致该应用程序包括公共html

这是我能想到的最简单的方案。

dist
  |- members
  |- index.html

其中“成员”是有角度的应用程序的根-在中指定(我尝试过并没有什么不同)

/index.html(称为主页)看起来像这样

<a href="members/login" >login</a>
<a href="members/register" >register</a>

应用路由器看起来像这样

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';    
import { RegisterComponent } from './components/register/register.component';
import { LoginComponent } from './components/login/login.component';
const appRoutes: Routes = [
    { path: '', component: LoginComponent, pathMatch: 'full' },
    { path: 'register', component: RegisterComponent, pathMatch: 'full' },
    { path: 'login', component: LoginComponent, pathMatch: 'full' }
    { path: '**', redirectTo: 'members/login' }
];    
@NgModule({
    imports: [
        RouterModule.forRoot( appRoutes )
    ],
    exports: [
        RouterModule
    ]
})
export class AppRoutingModule {}

我的4种情况1)输入“ localhost / index.html”-给我(主页)链接2)单击任一链接-给我(主页)3)在地址栏中输入“ localhost / members / login”或“ localhost / members / register”-给我(主页)链接4)在地址栏中输入“ localhost / members”-给我该应用程序

我缺少有关路由的信息...无法解决。 我希望我重提这个问题,并得到答案-

帮助请谢谢

尝试pathMatch:'full'作为默认组件

const appRoutes: Routes = [
    { path: '', component: ProfileComponent, pathMatch:'full' },
    { path: 'register', component: RegisterComponent },
    { path: 'login', component: LoginComponent },
    ...
    { path: '**', redirectTo: '/login' }
];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM