【发布时间】:2018-05-04 04:45:03
【问题描述】:
您好,我对 Angular 完全陌生,我也尝试了其他堆栈溢出答案。目前我正在从事 angular 4 项目。
根据我的项目,我现在只需要使用角度及其路由来创建设计。
我真正想要的是一个登录页面,一旦键入登录按钮需要转到另一个页面,其中水平左侧导航栏及其第一个子项处于活动状态,并且通过单击导航栏菜单,只需更改内容并且导航栏保持静态对于所有其他页面(仅登录除外)。
最后浏览了很多视频后,我创建了一个登录页面。我在 appcomponent.html 中编写了登录页面的代码,并将 routerlink 提供给按钮登录以打开登录页面。我的路由正常工作,一旦我点击登录,我的网址就会从 http://localhost:4200/ 更改为 http://localhost:4200/sidebar,但我的页面仍然只显示登录页面设计。
代码如下: index.html
<body >
<app-root></app-root>
</body>
app.component.ts
import { Component } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { SidebarComponent } from './sidebar/sidebar.component';
const appRoutes: Routes = [
{ path:'sidebar', component: SidebarComponent }
];
@NgModule({
declarations: [
AppComponent,
SidebarComponent,
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpModule
],
exports: [RouterModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.html
我只给了我给路由器链接的登录按钮代码,因为有很多代码
<div class="col-md-12 col-md-push-6 text-center">
<a routerLink="/sidebar" routerLinkActive="active"> <button id="Enter" class="btn btn-primary btn-block btn-flat fa fa-sign-in" > Log-In</button></a>
</div>
然后我在我想要呈现内容的导航栏页面中提供<router-outlet></router-outlet>。
由于目前我的一个不工作,我将 sidebar.htlm 页面编码更改为仅<h1> TESTING </h1>。我做错了什么?请帮忙。
【问题讨论】:
-
你能显示app.component.html的代码吗?
-
它只是一个登录页面的设计。只有我在登录按钮中给出的 routerlink 与其他项目不同。我上面也给出了那个路由器链接代码(因为设计代码很大,我只给出了按钮代码)。
标签: angular routing angular4-router