按钮点击路由跳转

现在外面导入Router模块

import {Router} from '@angular/router';
export class Demo04Component implements OnInit {
    constructor(private router:Router) {
        
     }

    // 定义一个跳转的方法
    // router navigateByUrl (path)
    jump(){
        this.router.navigateByUrl("demo02");
    }
    ngOnInit() { }
}

然后在html文件中button设置成这样


你可能感兴趣的:(按钮点击路由跳转)