angular - Angular Web 组件和路由
问题描述
我正在做一些有角度的网络组件,就像这个例子在这里说的。
所有 Web 组件在父应用程序中都可以正常显示(例如:http://localhost:8080/dashboard),但我当前的问题是我的 Web 组件中有一个按钮,我需要转到 Web 组件配置文件(例如:http ://localhost:8080/dashboard/profile)。
我尝试了几个例子,但没有一个有效。
有人可以指导我吗?先感谢您。
解决方案
您的一些代码将有助于查看您当前拥有的内容以及它可能出现的问题。
在您的 dashboard.component.html 文件中,您可能希望有一个链接到您的路由器的按钮或链接元素 ():
<a routerLink="/dashboard/profile">Login</a>
您的 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 { }
不要忘记在你的 app.module.ts 中导入你的路由模块。
app.module.ts
import { AppRoutingModule } from './app-routing.module';
推荐阅读
- google-apps-script - Google App 脚本 - 根据条件更新行(基于条件)
- 3d - 在 webgl 中绘制圆环
- javascript - 在网络浏览器中重新加载时滚动位置恢复规则
- c# - 是否可以为 C# nameof 运算符编写包装器?
- python - 如何在 flow_from_dataframe 中强制执行 class_indices 的映射
- jquery - 是否可以链接按钮以转到另一个页面并在其上打开模式?
- java - TableView 打印数据库中的空单元格
- shell - 如何在 shell 脚本中为变量分配特定时间(例如 12:00)?
- xamarin - 用户关闭应用程序时如何处理用户在 Xamarin iOS 上单击本地通知?
- listview - 如何像在颤动中使用列表视图一样创建一个喜欢的按钮?