Skip to content

Commit 6e8dda0

Browse files
committed
Access current router information
1 parent 01e41c2 commit 6e8dda0

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

README.md

+38-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
> Click :star:if you like the project. Pull Request are highly appreciated. Follow me [@SudheerJonna](https://twitter.com/SudheerJonna) for technical updates.
44
5+
---
6+
7+
<div align="center">
8+
<p>
9+
<a href="https://www.fullstack.cafe/?utm_source=github&utm_medium=sud">
10+
<b>Having Tech Interview?</b>
11+
<br> 3600 Tech Interview Questions. <b>Answered</b>.
12+
<br>
13+
<div>
14+
<img src="https://user-images.githubusercontent.com/13550565/76382460-cc784d80-6393-11ea-8837-2b89265ac853.png" width="260" alt="FullStack.Cafe">
15+
</div>
16+
</a>
17+
<sub><i>Proudly supporting Angular Interview Questions</i></sub>
18+
</p>
19+
</div>
20+
21+
---
22+
523
## Downloading PDF/Epub formats
624

725
You can download the PDF and Epub version of this repository from the latest run on the [actions tab](https://github.com/sudheerj/angular-interview-questions/actions).
@@ -280,7 +298,7 @@ You can download the PDF and Epub version of this repository from the latest run
280298
|268| [How do you optimize the performance of async validators?](#how-do-you-optimize-the-performance-of-async-validators)|
281299
|269| [How to set ngFor and ngIf on the same element?](#how-to-set-ngfor-and-ngif-on-the-same-element)|
282300
|270| [What is host property in css?](#what-is-host-property-in-css)|
283-
|271| [](#)|
301+
|271| [How do you get the current route?](#how-do-you-get-the-current-route)|
284302
|272| [](#)|
285303
|273| [](#)|
286304
|274| [](#)|
@@ -4509,4 +4527,22 @@ You can download the PDF and Epub version of this repository from the latest run
45094527
padding: 20px;
45104528
}
45114529
```
4512-
**[⬆ Back to Top](#table-of-contents)**
4530+
**[⬆ Back to Top](#table-of-contents)**
4531+
4532+
271. ### How do you get the current route?
4533+
In Angular, there is an `url` property of router package to get the current route. You need to follow the below few steps,
4534+
4535+
1. Import Router from @angular/router
4536+
```js
4537+
import { Router } from '@angular/router';
4538+
```
4539+
2. Inject router inside constructor
4540+
```js
4541+
constructor(private router: Router ) {
4542+
4543+
}
4544+
```
4545+
3. Access url parameter
4546+
```js
4547+
console.log(this.router.url); // /routename
4548+
```

0 commit comments

Comments
 (0)