历史前进/后退按钮不适用于 angular 2 路由器
History forward / backward button doesn't work with angular 2 router
History(推送状态)前进/后退按钮不适用于 angular 2 router.I 已在 Chrome 和 Firefox 中对此进行了测试。前进按钮从不工作,后退按钮只工作 2 步,而不是 UI 根据后退按钮没有响应。
我有以下代码。
app.component.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { CrisisListComponent } from './crisis-list.component';
import { HeroListComponent } from './hero-list.component';
import { Login } from './login';
@Component({
selector: 'my-app',
template: `
<h1>Component Router</h1>
<nav>
<a [routerLink]="['/home']">Crisis Center</a>
<a [routerLink]="['/login']">Login</a>
<a [routerLink]="['/heroes']">Heroes</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@Routes([
{path: '/home', component: CrisisListComponent},
{path: '/heroes', component: HeroListComponent},
{path : '/login' , component:Login},
{path: '*', component: CrisisListComponent}
])
export class AppComponent { }
login.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { LoginMobile } from './login/login_mobile';
import { LoginEmail } from './login/login_email';
@Component({
template: `
<h2>{{val}}</h2>
<p>Login here</p>\n\
<a [routerLink]="['/login/mobile']">Mobile</a>
<a [routerLink]="['/login/email']">Email</a>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@Routes([
{path : '/mobile' , component:LoginMobile},
{path : '/email' , component:LoginEmail}
])
export class Login {
val = "kwik.Social";
}
login/login_email.ts
import { Component } from '@angular/core';
@Component({
template: `
<p>Login here</p>
<input type="email" placeholder="Email" [(ngModel)]="email" />\n\
<p>Your Email is {{email}} </p>
`
})
export class LoginEmail {
email = "kwik.Social";
}
等了很久,试了一下router by NGRX team。它还有许多其他功能,如 Guards 、 Multiple Components 、 Child Components 和 Full History Api 支持。我唯一遗漏的一件事是历史 Api 本身不提供获取用户在文本字段和滚动位置上输入的值的方法,如果可用的话 Ajax 页面可能会变得更加流畅和一致.
编辑
NGRX 路由器现已弃用,Angular Router 受到 NGRX 路由器的启发并按预期工作。
History(推送状态)前进/后退按钮不适用于 angular 2 router.I 已在 Chrome 和 Firefox 中对此进行了测试。前进按钮从不工作,后退按钮只工作 2 步,而不是 UI 根据后退按钮没有响应。
我有以下代码。
app.component.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { CrisisListComponent } from './crisis-list.component';
import { HeroListComponent } from './hero-list.component';
import { Login } from './login';
@Component({
selector: 'my-app',
template: `
<h1>Component Router</h1>
<nav>
<a [routerLink]="['/home']">Crisis Center</a>
<a [routerLink]="['/login']">Login</a>
<a [routerLink]="['/heroes']">Heroes</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@Routes([
{path: '/home', component: CrisisListComponent},
{path: '/heroes', component: HeroListComponent},
{path : '/login' , component:Login},
{path: '*', component: CrisisListComponent}
])
export class AppComponent { }
login.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import { LoginMobile } from './login/login_mobile';
import { LoginEmail } from './login/login_email';
@Component({
template: `
<h2>{{val}}</h2>
<p>Login here</p>\n\
<a [routerLink]="['/login/mobile']">Mobile</a>
<a [routerLink]="['/login/email']">Email</a>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@Routes([
{path : '/mobile' , component:LoginMobile},
{path : '/email' , component:LoginEmail}
])
export class Login {
val = "kwik.Social";
}
login/login_email.ts
import { Component } from '@angular/core';
@Component({
template: `
<p>Login here</p>
<input type="email" placeholder="Email" [(ngModel)]="email" />\n\
<p>Your Email is {{email}} </p>
`
})
export class LoginEmail {
email = "kwik.Social";
}
等了很久,试了一下router by NGRX team。它还有许多其他功能,如 Guards 、 Multiple Components 、 Child Components 和 Full History Api 支持。我唯一遗漏的一件事是历史 Api 本身不提供获取用户在文本字段和滚动位置上输入的值的方法,如果可用的话 Ajax 页面可能会变得更加流畅和一致.
编辑
NGRX 路由器现已弃用,Angular Router 受到 NGRX 路由器的启发并按预期工作。