简体   繁体   English

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

[英]angular routing from static page / URL

Angular 5 (revised) Angular 5(修订版)

I have distilled my question, after an evening of reading and testing and trying different thing. 经过一晚上的阅读和测试并尝试了不同的方法之后,我已经提炼了我的问题。

The question becomes, How can I navigate to a path in my angular app, from OUTSIDE the app. 问题变成了,如何从应用程序外导航到我的角度应用程序中的路径。

I get the same result - both typing, and linking via href to any path OTHER than the app root, results in the app including the public html 我得到相同的结果-键入并通过href链接到除应用程序根目录以外的任何其他路径,会导致该应用程序包括公共html

Here is the simpliest scenario I could come up with. 这是我能想到的最简单的方案。

dist
  |- members
  |- index.html

where 'members' is the root of the angular app - specified in (I have tried it doesn't make a difference) 其中“成员”是有角度的应用程序的根-在中指定(我尝试过并没有什么不同)

the /index.html (call it the home page) looks like this /index.html(称为主页)看起来像这样

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

the app router looks like this 应用路由器看起来像这样

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 {}

My 4 scenarios 1) type "localhost/index.html" - gives me the (home page) links 2) clicking either link - gives me the (home page) 3) typing in the address bar "localhost/members/login" or "localhost/members/register" - gives me the (home page) links 4) typing in the address bar "localhost/members" - gives me the app 我的4种情况1)输入“ localhost / index.html”-给我(主页)链接2)单击任一链接-给我(主页)3)在地址栏中输入“ localhost / members / login”或“ localhost / members / register”-给我(主页)链接4)在地址栏中输入“ localhost / members”-给我该应用程序

I am missing something about routing... and cannot figure it out. 我缺少有关路由的信息...无法解决。 I hope me restating the problem, garners an answer - 我希望我重提这个问题,并得到答案-

help please thank you 帮助请谢谢

try pathMatch:'full' for the default component 尝试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