angular - 事件路由
问题描述
当用户单击菜单选项时,我想路由到特定页面。我已经创建了一个带有相应事件的方法,但我不知道如何路由到在菜单上单击的特定页面。
menuEvent(event: any): any {
if (event.item.label == 'First Page') {
// redirect to 'first-view'
}
}
路由已经在app-routing
模块中定义:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'first-view'
},
{
path: 'first-view',
component: FirstViewComponent
},
{
path: 'second-view',
component: SecondViewComponent
},
}
这似乎是一件非常简单的事情,但我是 Angular 的新手,所以还不能完全理解它。
解决方案
this.router.navigate(['/first-view']);
推荐阅读
- firebase - 导入firebase后反应本机错误
- python-3.x - 如何在 windows 环境下运行 pyinstaller
- java - 产生通量
从两个通量 - nginx - Nginx 配置问题
- c++ - 如何访问类内的类对象?
- android - 发布应用后 Google Drive Api 停止工作
- vba - Excel VBA 代码循环浏览文件夹、合并文件、创建图表然后保存在不同的位置
- django - 'is_superuser' is an invalid keyword argument for this function
- android - 设备旋转时可观察字段中的 Android 空值
- matlab - 在浏览器中试用的文档中给出的 matlab 文件存储在哪里