Angular 2 redirect on click

后端 未结 6 701
攒了一身酷
攒了一身酷 2020-12-15 20:20

How to create simple redirect on click on some button in Angular 2? Already tried:

import {Component, OnInit} from \'angular2/core\';
import {Router, ROUTER_         


        
6条回答
  •  抹茶落季
    2020-12-15 21:08

    I would make it more dynamic using method parameters

    Import the angular router

    import { Router } from '@angular/router';
    

    Create a button with click event

    My page

    Create a method with a pagename parameter

    redirect(pagename: string) {
      this.router.navigate(['/'+pagename]);
    }
    

    When clicked the router should route to the correct page

提交回复
热议问题