[英]Angular web components & routing
I am doing some angular web components like this example says here .我正在做一些 angular web 组件,就像这个例子在这里说的。
All web components are displayed fine in the parent app(example: http://localhost:8080/dashboard ) but my current problem is that I have a button in my web component and I need go to the web component profile (example: http://localhost:8080/dashboard/profile ). All web components are displayed fine in the parent app(example: http://localhost:8080/dashboard ) but my current problem is that I have a button in my web component and I need go to the web component profile (example: http ://localhost:8080/dashboard/profile )。
I have tried several examples but none worked.我尝试了几个例子,但没有一个有效。
Could someone guide me please?有人可以指导我吗? Thank you in advance.
先感谢您。
A little of your code would be useful to see what you currently have and what might be wrong with it.您的一些代码将有助于查看您当前拥有的内容以及它可能出现的问题。
In your dashboard.component.html file you would want to have a button or link element () which links to your router:在您的 dashboard.component.html 文件中,您希望有一个链接到您的路由器的按钮或链接元素 ():
<a routerLink="/dashboard/profile">Login</a>
Your app-routing.module.ts should have something along the lines of:您的 app-routing.module.ts 应该具有以下内容:
// standard imports
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
// importing your component to route to
import { DashboardProfileComponent } from './dashboardprofile/dashboardprofile.component';
// your route
const routes: Routes = [
{path: 'dashboard/profile', component: DashboardProfileComponent},
];
// standard
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Don't forget to import your routing module in your app.module.ts.不要忘记在你的 app.module.ts 中导入你的路由模块。
app.module.ts
import { AppRoutingModule } from './app-routing.module';
@beanic I found a workaround by using Inputs and Outputs with the web-component Output you will emit your target path and wrap your inside your web-component tags like: @beanic我找到了一种解决方法,将输入和输出与Web组件Output一起使用,您将发出目标路径并将您的Web组件标签包装在其中,例如:
<navigation><router-outlet></router-outlet></navigation>
and also add并添加
<ng-content></ng-content>
in web-component where you want your view to be loaded.在您希望加载视图的 Web 组件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.