| Start |
|---|
| ResolveData This example will show you how you can resolve data fetched from a service before rendering your application's view. Uses angular/router 3.0.0-beta.2 at the time of writing users.service.ts users.resolver.ts users.component.ts This is a page component with a list of all users. It will work similarly for User detail page component, replace app.routes.ts app.resolver.ts Optionally bundle multiple resolvers together. IMPORTANT: Services used in resolver must be imported first or you will get a 'No provider for ..Resolver error'. Remember that these services will be available globally and you will not need to declare them in any component's main.browser.ts Resolvers have to be injected during bootstrapping. |
| Routing with Children Contrary to original documentation, I found this to be the way to properly nest children routes inside the app.routing.ts or app.module.ts file (depending on your preference). This approach works when using either WebPack or SystemJS. The example below shows routes for home, home/counter, and home/counter/fetch-data. The first and last routes being examples of redirects. Finally at the end of the example is a proper way to export the Route to be imported in a separate file. For ex. app.module.ts To further explain, Angular requires that you have a pathless route in the children array that includes the parent component, to represent the parent route. It's a little confusing but if you think about a blank URL for a child route, it would essentially equal the same URL as the parent route. |
| Basic Routing Router enables navigation from one view to another based on user interactions with the application. Following are the steps in implementing basic routing in Angular 2 - Basic precaution: Ensure you have the tag as the first child under your head tag in your index.html file. This tag tells that your app folder is the application root. Angular 2 would then know to organize your links. First step is to check if you are pointing to correct/latest routing dependencies in package.json - Second step is to define the route as per it's class definition - In a routes file ( Routes are made available to application via dependency injection. ProviderRouter method is called with RouterConfig as parameter so that it can be injected to the components for calling routing specific tasks. Third step is to bootstrap the route provider. In your Fourth step is to load/display the router components based on path accessed. directive is used to tell angular where to load the component. To use import the ROUTER_DIRECTIVES. Fifth step is to link the other routes. By default, RouterOutlet will load the component for which empty path is specified in the RouterConfig. RouterLink directive is used with html anchor tag to load the components attached to routes. RouterLink generates the href attribute which is used to generate links. For Ex: Now, we are good with routing to static path. RouterLink support dynamic path also by passing extra parameters along with the path. import { Component } from '@angular/core'; import { ROUTER_DIRECTIVES } from '@angular/router'; RouterLink takes an array where first element is the path for routing and subsequent elements are for the dynamic routing parameters. |
| Child Routes Sometimes it makes sense to nest view's or routes within one another. For example on the dashboard you want several sub views, similar to tabs but implemented via the routing system, to show the users' projects, contacts, messages ets. In order to support such scenarios the router allows us to define child routes. First we adjust our Now that we have our child routes defined we have to make sure those child routes can be displayed within our As you can see, we have added another So by adding the empty route, meaning a route with an empty path, we have defined an entry point for the router. |
Read Article
https://develop.horje.com/learn/1434/reference