I searched the net to get an example of angular2 router that changes browser urls. All examples that are there doesn't change browser urls when we change different routes. Can you give me a small example in ES6 to demonstrate this?
Angular 2 routing
2.9k views Asked by Vinz and Tonz At
3
There are 3 answers
2
On
After digging into Angular2 source code, I figured out one way to get dynamic routing to work. Let's see this example:
import {Router} from 'angular2/router';
@Component({
...
})
export class SampleComponent {
public router: Router;
constructor(router: Router) {
this.router = router;
}
goTo(uri) {
this.router.navigateByUrl(uri);
}
}
An example.
On a Component class:
name
is not necessary, but can be used to provide an alias.In the template:
Note that
router-link
must exist on an<a>
tag.