使用angular2构建应用时遇到问题。
我在两个数组中定义//Action in B controller
public function beforeFilter()
{//not completelly necessary but handy. You can recover directly the data
//from session in the action
if($this->Session->check('previousPageInfo'))
{$this->data = $this->Session->read('previousPageInfo')};
parent::beforeFilter();
}
public function processFromPreviousPage()
{
//do what ever you want to do. Data will be in $this->data or
// if you like it better in $this->request->data
$this->processUserData($this->request->data);
//...
}
:
appRoutes.ts
routes
App.ts:在var beforeLogin = [
{ path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true },
{ path: '/login', name: 'Login', component: LoginComponent },
{ path: '/**', name: ' ', redirectTo: ['Home'] }
],
afterLogin = [
{ path: '/about', name: 'About', component: AboutComponent, useAsDefault: true },
{ path: '/**', name: ' ', redirectTo: ['About'] }
];
注册routes
,将RouterConfig
注册为NavbarComponent
derective
navbar.ts:
@Component({
selector: 'main-app',
templateUrl: './src/app/app.html',
directives: [RouterOutlet, NavbarComponent],
pipes: [TranslatePipe]
})
@RouteConfig(APP_ROUTES) //register routes config
navbar.html
export class NavbarComponent {
private routeList: RouteDefinition[];
constructor() {
this.routeList = APP_ROUTES;
this.isLogin = Security.getLogin();
}
logout() {
this.updateNavbar();
}
updateNavbar() {
}
}
我希望<ul class="nav navbar-nav">
<li *ngFor="#route of routeList"><a [routerLink]="[route.name]">{{route.name}}</a></li>
</ul>
可以在登录/注销应用时重新呈现。登录后无法在navbar
路线中加载路线(重定向到beforeLogin
等等),反之亦然
Home
:加载应用时显示在beforeLogin
navbar
:登录后显示在afterLogin
。
对我而言,谢谢。