【发布时间】:2018-08-06 02:18:39
【问题描述】:
Angular 5(修订版)
经过一晚上的阅读、测试和尝试不同的事情,我提炼了我的问题。
问题变成了,如何从应用程序外部导航到我的 Angular 应用程序中的路径。
我得到相同的结果 - 无论是键入还是通过 href 链接到除应用程序根目录以外的任何路径,都会导致应用程序包括公共 html
这是我能想到的最简单的方案。
dist
|- members
|- index.html
'members' 是 Angular 应用程序的根 - 在中指定(我已经尝试过,但没有区别)
/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' 并将其添加到默认组件并检查 index.html 中的