Angular 2 navigation is configured using the routerLink
directive. The routerLink directive behaves like an href’s you are familiar with, but it hooks into Angular 2’s router to navigate between your defined routes.
app.component.html:
<nav> <a routerLink="">Home</a> <a routerLink="contact">Contact</a> </nav> <router-outlet></router-outlet>
app.routers.ts:
import {HomeComponent} from "./home/home.component"; import {RouterModule} from "@angular/router"; import {ContactComponent} from "./contact/contact.component"; const routes = [ {path: ‘‘, component: HomeComponent}, {path: ‘contact‘, component: ContactComponent}, ]; export default RouterModule.forRoot(routes);
时间: 2024-10-21 05:37:24