【发布时间】:2017-01-08 00:05:21
【问题描述】:
我已经在网上搜索了关于如何在手动输入 url(或页面刷新)时导航到 Angular2 中的特定组件的基本了解。除了将近 2 年的 beta angular2 实现(Such as here)之外,我找不到任何东西。我有一个使用 node/express 的简单 Angular Web 应用程序。让客户端导航工作正常,但让客户端处理服务器请求我不确定这是如何工作的,甚至不确定如何实现。谁能帮忙。
我只是在做: http://localhost:3000/login - 在应用程序中导航时效果很好,但是当我刷新时它不起作用。我认为关于如何简单地实现这一点会有大量资源,但我没有找到基本的东西。谢谢!
main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { AppComponent } from './components/app.component';
import { LoginComponent } from './components/auth/login';
import { IndexComponent } from './components/home/index';
import { PageNotFoundComponent } from './components/not-found.component';
@NgModule({
imports: [ BrowserModule,
RouterModule.forRoot([
{
path: 'login',
component: LoginComponent
},
{
path: '',
component: IndexComponent
},
{ path: '**', component: PageNotFoundComponent }
])],
declarations: [ AppComponent,IndexComponent,LoginComponent,PageNotFoundComponent ],
providers: [ ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
【问题讨论】:
标签: node.js angular angular2-routing angular2-template