user3601578
user3601578

Reputation: 1362

Dynamic path in Angular2 Router

I'm looking for a way to receive the current server path as a string in Angular2, i.e.

http://localhost:3000/my/dynamic/path

How can I get: /my/dynamic/path

Upvotes: 0

Views: 170

Answers (2)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657068

This should do it the Angular way

export class AppComponent {
    constructor(private location:Location) {}    
    repoPath: string;
    ngOnInit() {
        this.repoPath = location.path();
    }
}

Upvotes: 1

user3601578
user3601578

Reputation: 1362

Found it already:

export class AppComponent {
    repoPath: string;
    ngOnInit() {
        this.repoPath = window.location.pathname;
    }
 }

Upvotes: 0

Related Questions