在角度为6

时间:2018-10-26 04:08:06

标签: angular6 url-routing angular-router base-url

我在index.html中给出了basehref

登录后的应用程序URL:http:localhost:4200 / Project_Name / dashboard

app.routing.module

`const routes: Routes = [{path: '',redirectTo: 'dashboard',pathMatch: 'full'},{path: 'header', component: 'HeaderComponent'},{path: 'footer', component: 'FooterComponent'},{path: 'dashboard', component: 'DashboardComponent'}]

DashboardComponent.ts

import {Router} from '@angular/router';
 constructor(private _route: Router){}
 ngOnInit(){
       this._route.events.pipe(filter(event => event instanceof 
         NavigationStart)
          ).subscribe(value => {
              console.log(value['url']);
              })
        }

单击导航到HeaderComponent时,我有一个带有[routerLink]="['/header']"的按钮

如果用户从DashboardComponent导航到HeaderComponent,则会触发_router.events并在console.log(/ header)中显示HeaderComponent网址;

如果我将网址发送到this_route.navigate([value]);

我导航到404页面,因为网址是http://localhost:4200/header而不是http://localhost:4200/Project_Name/header

如何在路由器url中也包括basehref?

0 个答案:

没有答案