当前位置: 首页 > 知识库问答 >
问题:

使用router.navigate的角度路由

屈升
2023-03-14

我正在尝试从当前组件导航到另一个组件,如下所示:

this.router.navigate(['/relationshipInfo']);

上面的语句没有路由到其他组件,下面是我在app-routing.module.ts中的代码:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {PersonalInfoComponent} from './PersonalInfo/PersonalInfo.component';
import {RequiredInfoComponent} from './RequiredInfo/RequiredInfo.component';
import {RelationshipInfoComponent} from './relationshipInfo/relationshipInfo.component'

const routes: Routes = [

  {path: 'PersonalInfo', component: PersonalInfoComponent},
  {
    path: '',
    children: [
      {path: 'RequiredInfo', component: RequiredInfoComponent},
      {path: 'RelationshipInfo', component: RelationshipInfoComponent},

  ]

  },

  {path: '**', redirectTo: 'PersonalInfo', pathMatch: 'full'},

];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

下面是我的app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { PersonalInfoComponent } from './PersonalInfo/PersonalInfo.component';
import { MaterialModule } from './shared/Material.Module';
import { FormsModule } from '@angular/forms';
import { RequiredInfoComponent } from './RequiredInfo/RequiredInfo.component';
import { RelationshipInfoComponent } from './relationshipInfo/relationshipInfo.component';

@NgModule({
   declarations: [
      AppComponent,
      PersonalInfoComponent,
      RequiredInfoComponent,
      RelationshipInfoComponent
   ],
   imports: [
      BrowserModule,
      AppRoutingModule,
      MaterialModule,
      FormsModule
   ],
   providers: [],
   bootstrap: [
      AppComponent
   ]
})
export class AppModule { }

我正在尝试通过单击我的按钮进行路由。该按钮存在于“个人信息”页面中。下面是 HTML 和 .ts 代码:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-PersonalInfo',
  templateUrl: './PersonalInfo.component.html',
  styleUrls: ['./PersonalInfo.component.css']
})
export class PersonalInfoComponent implements OnInit {
  public Loaded = false;
  public btnshow=true;
  constructor(private router:Router) { }

  ngOnInit() {
  }

  onlinePage(){
    this.router.navigate(['/RelationshipInfo']);
    this.router.navigateByUrl('/RelationshipInfo');
  }

  Continue()
  {
    //this.router.navigate(['/RequiredInfo']);
    this.router.navigateByUrl('/RequiredInfo');

  }

  Cancel(){}

}

任何帮助都将不胜感激。

共有1个答案

锺离俊雄
2023-03-14

角度路由路径区分大小写。您将路由定义为:

{path: 'RelationshipInfo', component: RelationshipInfoComponent},
this.router.navigate(['/RelationshipInfo']);
 类似资料:
  • 使用其他文本消息不是一个好方法,因为如果枚举中有数百个值,那该怎么办。我不会在html代码中重复枚举。

  • 问题内容: 角度ui路由器的示例演示在起始页面具有以下链接: “ ui-router”的完整网址为或 “关于”的完整网址为或 当我使用durandalJS时,存在一个限制,即默认URL只是“ /”,不能有“ / ui-router”。 Angular ui路由器插件有相同的限制吗? 问题答案: 请参阅此处,默认路由有一个“其他”选项。

  • 应用程序模块: app-routing.module.ts: 实体/实体-routing.module.ts: 实体/实体.组件. ts: 我还尝试使用以下方法在实体模块中定义路由,但组件仍会显示为导航到 /list,而不是 /entities/list。 我做错了什么?任何帮助是值得赞赏的!

  • 问题内容: 在ios8中可用的角度应用程序中进行路由会在ios9中产生[$ rootScope:infdig]错误。我都尝试过,但是结果是一样的。 有什么解决办法吗? 问题答案: 即使这被标记为该问题的重复。这是解决此问题的最佳方法。 ionic app iOS 9问题$ rootScope:infdig达到10个$digest()迭代 这篇文章中的选定答案将您带到该插件,该插件用angular修

  • 是否可以在 Angular 2 路由中具有可选的路由参数?我在RouteConfig中尝试了Angular 1.x语法,但收到以下错误: “原始异常:路径“/ user /: id ?“包含”?

  • 我在角度4中使用路由时遇到了一点问题。你知道,当我尝试使用将数据从一个组件传递到另一个组件时,我刚刚收到了。 组成部分 界面 发送方法