angular2-routing

Angular2 get current route's alias

别等时光非礼了梦想. 提交于 2019-12-12 07:26:17
问题 I'm able to get current route's path like: /about, /, /news with location.path(). But how can I get its alias instead (the 'as' part in the definition of a route)? { path: '/about', as: 'About', component: About } Is it possible? 回答1: NOTE: The following has been tested with the 2.0 beta series. The RC versions have an updated router component with breaking changes. The old one has been renamed to router-deprecated . This has not been tested yet against the new router. The following will

Dynamic Route Loading in Angular 2 Fails. (Beta)

风格不统一 提交于 2019-12-12 07:21:11
问题 I want to load routes for the @RouteConfig Dynamically from a service which fetches in format JSON, [ { "path" : "/about" , "name" : "About" , "component" : "AboutComponent" }, { "path" : "/contact" , "name" : "Contact" , "component" : "ContactComponent" } ] Following is the code for pushing it into the RouteDefinition Array, for (let i = 0; i < data.length; i++) { //console.log(data[i].path+" "+data[i].name+" "+data[i].component); this.routeConfigArray.push({ //routeConfigArray :

Angular 2: Inject a dependency into @CanActivate?

人走茶凉 提交于 2019-12-12 07:14:50
问题 In Angular 2, you can specify a @CanActivate annotation for a component where you can determine if the component should be activated or not. The reason it's not an interface is because the callback is called before the component is even instantiated. The problem is, I can't figure out a way to get dependencies injected into that callback. And I need my service that tells me whether I'm logged in or not (and as whom) to determine whether routing to a particular component is allowed or not. How

Does angular2 support nested states/routes?

此生再无相见时 提交于 2019-12-12 07:09:19
问题 Does angular2 support nested states/routes? for example in a view port there are 2 links and on clicking a specific link it will present a view which with further have more than one link but that are specific to earlier link. 回答1: Yes. I made some demo: http://plnkr.co/edit/IcnEzZ0WtiaY5Bpqrq2Y?p=preview import {Component, View, Input} from 'angular2/core'; import { RouteConfig, Router, RouteParams, ROUTER_DIRECTIVES } from 'angular2/router'; import {PersistentRouterOutlet} from './persistent

How to reuse a Single Component with multiple routes without creating instance of Component again

霸气de小男生 提交于 2019-12-12 06:57:20
问题 I am having two routes the first will get the list and the second get the details for each single item in a list. Initially I am displaying few values for each element in list with an action link and when the link is clicked it passes an id to method viewCoupon() and the route changes resulting in an error. How should I avoid creating an instance again and just call a different route. The code looks like below. export class CouponsComponent implements OnInit{ public couponList: Array<Coupons>

Where to upload image in angular 2 project?

早过忘川 提交于 2019-12-12 06:46:31
问题 I have an app that can upload images. Everything is working fine, I;m not having issues with the upload itself... But I have issues because as soon as I upload the image and storage in the server, the angular-clie reload the page. At first, I was uploading the images to /src/assets Then I relized that angular-clie is refreshing the page, because it detect some new content on the folder it's listeing. So I change that and now the images are being uploading to /resources (outside src folder) so

Angular2 Routing with parameters fails

馋奶兔 提交于 2019-12-12 06:15:11
问题 I am having troubles (all sorts of errors in very unexpected places) and my best guess is that it happens because of the way routing is set up. This is my app-routing.module.ts const appRoutes: Routes = [ { path: 'calendar', component: CalendarComponent, canActivate: [AuthGuard] }, { path: 'calendar/:urlString', component: CalendarComponent, canActivate: [AuthGuard] }, { path: 'myprofile', component: ProfileComponent, canActivate: [AuthGuard] }, { path: 'profiles', component: ProfileComponent

Angular 2 Different modules same routing

人盡茶涼 提交于 2019-12-12 05:49:26
问题 I am having two main routes, both loading same child module. Is there any possible way to have two routes with same name on the child module that loads two different components with respect to the main route. Main Routes : export const ROUTES: Routes = [{ path: 'first', loadChildren: './features/common#CommonModule', canActivate: [AppAuthGuard] }, { path: 'second', loadChildren: './features/common#CommonModule', canActivate: [AppAuthGuard] }] Now I'm expecting the common module to have routes

Angular 2 routes current url with params

守給你的承諾、 提交于 2019-12-12 05:36:47
问题 I'm trying to use Angular 2 rc-4 with new Router. export const appRoutes: RouterConfig =[ { path: "", component: HomeComponent, terminal: true, data: { title: "Home" } }, { path: "Users", component: UserListComponent, data: { title: "Users" } }, { path: "Users/:id", component: UserEditComponent, data: { title: "Edit User" } } ]; Then I subscribe to change route event. When event fires I want to find item from appRoutes The problem is with url with params: Users/:id I don't know how to compare

Can't get app to navigate to portal

霸气de小男生 提交于 2019-12-12 05:16:22
问题 I'm trying to write a route guard. Here's my route... { path: 'portal', component: PortalComponent, canActivate: [AuthGuard] } And here's AuthGuard: @Injectable() export class AuthGuard implements CanActivate { constructor(private appState: ApplicationState, private router: Router) {} canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { let url: string = state.url; return this.checkLogin(url); } checkLogin(url: string): Observable<boolean> { return