angular2-routing

Cannot get query Params on routerOnActivate

五迷三道 提交于 2019-12-20 04:15:07
问题 Im having problems trying to get query params using the new Route library. VERSION 2.0.0-rc.1 Problem routerOnActivate(curr:RouteSegment, prev?:RouteSegment, currTree?:RouteTree, prevTree?:RouteTree):void { console.log(curr.getParam("test")); } Always prints undefined Another problem is that my url gets "reseted" everytime (Thats why i think curr.getParam("test") returns undefined) Here is my App Component and My Home Component : APP COMPONENT import {Component} from '@angular/core'; import {

Delay navigating to next page

痴心易碎 提交于 2019-12-20 02:13:57
问题 My angular site works great, but when you click into a project it loads the page, right away and sometimes there is a flash while the images are pulled from the API , id like a 1 second delay, or page transition effect. but i'm not sure how to implement this in Angular 2. Interested to hear what others are doing ? Thanks in advance 回答1: You can implement CanDeactivate interface, something like this: routerCanDeactivate(currTree?: RouteTree, futureTree?: RouteTree): Promise <boolean> { return

How can I specify query parameters by routerLink directive

这一生的挚爱 提交于 2019-12-19 17:45:32
问题 I am experimenting the new router (version 3.0.0-alpha.7) and would like to know how to specify query parameters by routerLink directive? The Router.navigate() method below generates a URL like http://localhost:3000/component-a?x=1 this.router.navigate(['/component-a'], {queryParams: {x: 1}}); However, I can't figure out how to do the same thing with the routerLink directive. Template like below returns parser error... <a [routerLink]="['/component-a'], {queryParams: {x: 1}}">Component A</a>

Clear all queryParams with new Router v3 Angular2

点点圈 提交于 2019-12-19 12:28:13
问题 I'm trying to figure out how to use the Angular2 router navigation (router 3.0.0-alpha.7) with query parameters. I can easily navigate to a route with a queryParam with this line: this._router.navigate(['/login'], {queryParams: {redirect: 'route1'}}); In the '/login' component, I do some login which will redirect to the redirect route, namely route1 here. However, after the redirection, the redirect query parameters stays in the URL, i.e. I'm now at page /route1?redirect=route1 . I want to

Clear all queryParams with new Router v3 Angular2

孤街醉人 提交于 2019-12-19 12:28:13
问题 I'm trying to figure out how to use the Angular2 router navigation (router 3.0.0-alpha.7) with query parameters. I can easily navigate to a route with a queryParam with this line: this._router.navigate(['/login'], {queryParams: {redirect: 'route1'}}); In the '/login' component, I do some login which will redirect to the redirect route, namely route1 here. However, after the redirection, the redirect query parameters stays in the URL, i.e. I'm now at page /route1?redirect=route1 . I want to

Do aux routes work for the root component only?

扶醉桌前 提交于 2019-12-19 07:16:07
问题 I'm having trouble setting up auxiliary routes in child components, for some reason only those auxiliary routes work that start at the root component. Here's my router setup export const routes: RouterConfig = [ { path: 'test1', component: Test1Component }, { path: 'test2', component: Test2Component, outlet: 'aux'}, { path: 'shell', component: ShellComponent, children: [ { path: 'department/:id', component: DepartmentDetailComponent }, { path: 'test3', component: Test3Component, outlet: 'aux2

Angular 4 Component ngOnInit not called on each route request

青春壹個敷衍的年華 提交于 2019-12-19 06:19:33
问题 I just recently started diving into Angular 4 coming from Angular 1.5. I'm working with user routes and pulling API data from a service into a user component. The component seems to stay static unlike controllers in 1.* where they were refreshed on each request. Is there anyway to have the ngOnInit function called on each new route request? My user component class: // url structure: /user/:id export class UserComponent implements OnInit { constructor(private route: ActivatedRoute) {} ngOnInit

How to manipulate a component on specific routes in Angular2

耗尽温柔 提交于 2019-12-19 05:43:07
问题 I have a simple TopbarComponent which basically adds a bootstrapish navbar at the top of my view. Since 90% of my templates should have this directive included, i want to handle it through my app.component which looks like this: import ...; @Component({ selector: 'my-app', templateUrl: 'app/app.component.html', directives: [ROUTER_DIRECTIVES, TopbarComponent, ...], providers: [ROUTER_PROVIDERS, ...] }) @RouteConfig([ { path: '/login', name: 'Login', component: LoginComponent }, { path: '

Invoke component refresh in Angular 2

ぃ、小莉子 提交于 2019-12-19 04:25:10
问题 I am trying to implement a navbar that shows different links based on whether or not a user is logged-in. I am using the angular2-jwt library which provides the tokenNotExpired() function. I have 2 routes, /home and /login . I have a navbar component which is outside of the <router-outlet> , which means it is initialized only once and not every time the route changes. After successful login, I am invoking router.navigate(['/home]) . The home and login both have checks for if a user is logged

Angular 2 => notify a route component of an event in the app component

烈酒焚心 提交于 2019-12-18 18:20:21
问题 Slowly getting to grips with angular 2 but I've come to dead end on one particular issue. If you have this arrangement; <parent> <child/> </parent> I can notify the child of changes in the parent by using @Input() and get it to listen to changes. I can notify the parent of changes in the child by using the @Output() and EventEmitters. What I'm now looking at is notifying a routed component (a component that is loaded dynamically when a link it clicked) about a specific event that happens in