欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Angular实现登录注册页面路由跳转

程序员文章站 2024-03-30 20:54:57
app.module.ts:import { BrowserModule } from '@angular/platform-browser';import { NgModule } from '@angular/core';// import { RouterModule } from '@angular/router';import { RouterModule, Routes } from '@angular/router';import { AppComponent } from './a...

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
// import { RouterModule } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { LoginDemoComponent } from './login-demo/login-demo.component';
import { RegisterDemoComponent } from './register-demo/register-demo.component';

const appRoutes: Routes = [
  { path: 'login-demo', component: LoginDemoComponent },
  { path: 'register-demo', component: RegisterDemoComponent },
  { path: '',   redirectTo: '/login-demo', pathMatch: 'full' },
];

  imports: [
    BrowserModule,
    RouterModule.forRoot([
      {path: 'login-demo', component: LoginDemoComponent},
      {path: 'register-demo', component: RegisterDemoComponent},
      { path: '',   redirectTo: '/login-demo', pathMatch: 'full' },
     
  ]),
  ],

app.component.html:

<router-outlet></router-outlet>

bootstrap样式 在style.css里面全局配置

@import "~bootstrap/dist/css/bootstrap.css";

登录页面跳转:

<div class="col-sm-offset-2 col-sm-10 ">
                            <a class="button btn-success" routerLink="/register-demo" routerLinkActive="activebutton">Sign in</a>
                            <button class="btn btn-default " routerLink="/register-demo">Sign in</button>
                        </div>

本文地址:https://blog.csdn.net/weixin_45202083/article/details/109278810