[Angular 2] Router Basic and Router Params

Source: Internet
Author: User

    • When we define router in Angualr 2, we use @RouteConcfig ()
    • When we want to display component, we <router-outlet>
    • When we want to navigate to component, we use [routerlink]= "[' Routername ']"
    • When we want to access router params, we use Routerparams
    • When we want to access Rotuer itself, we use Router

1. In index.html:

<href= "/">

2. Include Router file:

Import ' Angular2/router ';

3. Inject the provider:

Bootstrap (APP, [    router_providers]);

4. @RouterConfig:

@RouteConfig ([    True},    '/about ', Name: ' About ', component:aboutcomponent}]) 

5. Inject router_directives:

router_directives],

6. Define the link:

        <a href= "" [routerlink]= "[' Home ']" >Home</a>        <a href= "" [routerlink]= "[' home ', {username: ' Hero '} ] ">Owner</a>        <a href=" "[routerlink]=" [' About '] ">About</a>

7. Define the Router-outlet:

        <nav>            <a href= "" [routerlink]= "[' Home ']" >Home</a>            <a href= "" [routerlink]= "[' home ', { Username: ' Zhentian Wan '}] ">Owner</a>            <a href=" "[routerlink]=" [' About '] ">About</a>        </nav>        <router-outlet></router-outlet>

8. If deal with Routerparams:

    Constructor (private _routeparams:routeparams) {        this. Username = _routeparams.get (' Username ');    }

----------------

[Angular 2] Router Basic and Router Params

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.