如何定义用于从具有数据的URL加载上一个组件的路由?

发布于 2025-01-27 13:11:14 字数 1722 浏览 4 评论 0原文

以下是我

const routes: Routes = [
  {
    path: 'nav',
    component:NavComponent,
    children:[
      {
        path: 'basic-profile',
        component: BasicProfileComponent
      },
      {
        path: 'search',
        component: SearchComponent
      },
      {
        path:'business-profile',
        component: BusinessProfileComponent
      },
      {
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
      },
      {
        path:'messaging',
        component: MessagingComponent,
      }
   
    ]
  },
  
];

在URL的

路线

http:// localhost:4200/nav/search/business-card-full-view/10

     {
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
      },

我想去

http:// localhost:4200/nav/messaging

     {
        path:'messaging',
        component: MessagingComponent,
      }

通过单击一个按钮来发送此URL。

<button mat-button routerLink="messaging">Message</button>

按钮在BusinessCardfullviewComponent中。

我该怎么做?

我也尝试 redirectto

{
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
        children:[
              {
                path:'messaging',
                redirectTo:'messaging',
              }
            ]
      },

但不起作用!

我使用路由器进行工作,如下所示

messaging()
  {
    this.router.navigate(['nav/messaging']);
  }

Following are my routes

const routes: Routes = [
  {
    path: 'nav',
    component:NavComponent,
    children:[
      {
        path: 'basic-profile',
        component: BasicProfileComponent
      },
      {
        path: 'search',
        component: SearchComponent
      },
      {
        path:'business-profile',
        component: BusinessProfileComponent
      },
      {
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
      },
      {
        path:'messaging',
        component: MessagingComponent,
      }
   
    ]
  },
  
];

I am at URL

http://localhost:4200/nav/search/business-card-full-view/10

     {
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
      },

I want to go the

http://localhost:4200/nav/messaging

     {
        path:'messaging',
        component: MessagingComponent,
      }

this URL by clicking one button.

<button mat-button routerLink="messaging">Message</button>

button is in BusinessCardFullViewComponent.

How can I do this?

I try redirectTo also

{
        path:'search/business-card-full-view/:businessAccountId',
        component: BusinessCardFullViewComponent,
        children:[
              {
                path:'messaging',
                redirectTo:'messaging',
              }
            ]
      },

But not working!

I do my work using Router as follows

messaging()
  {
    this.router.navigate(['nav/messaging']);
  }

It works..!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文