angular2-routing

Angular 2 router.navigate

本秂侑毒 提交于 2019-11-27 01:00:30
问题 I'm trying to navigate to a route in Angular 2 with a mix of route and query parameters. Here is an example route where the route is the last part of the path: { path: ':foo/:bar/:baz/page', component: AComponent } Attempting to link using the array like so: this.router.navigate(['foo-content', 'bar-contents', 'baz-content', 'page'], this.params.queryParams) I'm not getting any errors and from what I can understand this should work. The Angular 2 docs (at the moment) have the following as an

angular 2 azure deploy refresh error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable

橙三吉。 提交于 2019-11-27 00:52:42
问题 I have an Angular 2 rc-2 app with basic routing implemented.The paths are /path1 which is the default path and /path2 .The home path / redirects to /path1 . When I run it locally (lite-server) everything works fine. I managed to deploy this app to an Azure web app. The app works OK BUT if I refresh the page when I m in /path1 or /path2 I get this error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. A possible approach is to implement

Angular 2 - replace history instead of pushing

依然范特西╮ 提交于 2019-11-27 00:52:29
问题 How to replace a history instead a pushing a new in angular 2's new router (rc.1)? For example Im in a question list ( /questions ) opening a new modal in a new route ( /questions/add ), and after adding a new question I go to the question view ( /questions/1 ). If I press back I would like to go to the /questions instead of /questions/add 回答1: If you use router.navigate And then location.replaceState With the exact same path, you can trigger changes that usually happen, as well as replacing

Pass parameter into route guard

半世苍凉 提交于 2019-11-27 00:49:18
问题 I'm working on an app that has a lot of roles that I need to use guards to block nav to parts of the app based on those roles. I realize I can create individual guard classes for each role, but would rather have one class that I could somehow pass a parameter into. In other words I would like to be able to do something similar to this: { path: 'super-user-stuff', component: SuperUserStuffComponent, canActivate: [RoleGuard.forRole('superUser')] } But since all you pass is the type name of your

How to get parameter on Angular2 route in Angular way?

被刻印的时光 ゝ 提交于 2019-11-27 00:46:27
问题 Route const appRoutes: Routes = [ { path: '', redirectTo: '/companies/unionbank', pathMatch: 'full'}, { path: 'companies/:bank', component: BanksComponent }, { path: '**', redirectTo: '/companies/unionbank' } ] Component const NAVBAR = [ { name: 'Banks', submenu: [ { routelink: '/companies/unionbank', name: 'Union Bank' }, { routelink: '/companies/metrobank', name: 'Metro Bank' }, { routelink: '/companies/bdo', name: 'BDO' }, { routelink: '/companies/chinabank', name: 'China Bank' }, ] }, ...

Angular2 routing / deep linking not working with Apache 404

空扰寡人 提交于 2019-11-27 00:33:13
I am following the Angular 2 routing examples. Using the "lite" webserver I am able to navigate from the root and deep linking works, but using Apache I can navigate from the root, but get 404 Not Found errors when following links direct to routes. For example the following URL works against the "lite" webserver started on port 3000 by npm. http://localhost:3000/crisis-center/2 But the next URL against Apache running on port 80 fails. http://localhost/crisis-center/2 The requested URL /crisis-center/2 was not found on this server. I did try a few .htaccess solutions recommended for similar

How to determine previous page URL in Angular?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 00:26:01
Suppose I am currently on the page which has the URL /user/:id . Now from this page I navigate to next page :id/posts . Now Is there a way, so that i can check what is the previous URL, i.e. /user/:id . Below are my routes export const routes: Routes = [ { path: 'user/:id', component: UserProfileComponent }, { path: ':id/posts', component: UserPostsComponet } ]; Günter Zöchbauer You can subscribe to route changes and store the current event so you can use it when the next happens previousUrl: string; constructor(router: Router) { router.events .filter(event => event instanceof NavigationEnd)

Angular 2: getting RouteParams from parent component

送分小仙女□ 提交于 2019-11-27 00:16:32
How do I get the RouteParams from a parent component? App.ts : @Component({ ... }) @RouteConfig([ {path: '/', component: HomeComponent, as: 'Home'}, {path: '/:username/...', component: ParentComponent, as: 'Parent'} ]) export class HomeComponent { ... } And then, in the ParentComponent , I can easily get my username param and set the child routes. Parent.ts : @Component({ ... }) @RouteConfig([ { path: '/child-1', component: ChildOneComponent, as: 'ChildOne' }, { path: '/child-2', component: ChildTwoComponent, as: 'ChildTwo' } ]) export class ParentComponent { public username: string;

Routing and navigation in Angular 2

给你一囗甜甜゛ 提交于 2019-11-26 23:28:03
问题 I am going through the tutorials for Angular 2 and have been able to get a simple application up and running. Now, I am moving on to the routing and navigation part found here https://angular.io/docs/ts/latest/guide/router.html, but something isn't working for me. I went to the live example in Plunker and downloaded the code from there. I then setup a solution in Visual Studio 2015 and plugged in all of the code from the Plunker download. The application works perfectly except for one thing,

Is Angular 2's Router broken when using HTML5 routes? [duplicate]

一个人想着一个人 提交于 2019-11-26 22:53:16
This question already has an answer here: Angular 2.0 router not working on reloading the browser 32 answers This whole new routes syntaxis sounded to good to be true and now I'm thinking it actually is. I gave up trying to make it work and here I am noticing that not even the main example in the Angular 2 page works. If you open the live example and you try it just clicking it works cool and you can see the path in the url gets changed, but it is only changing the String the path doesn't really exists, if you copy your url and sending it to someone they will get the following error: {