# Getting Current user route and path

**URL:** https://meta.discourse.org/t/getting-current-user-route-and-path/56723
**Category:** Development
**Created:** [February 1, 2017, 5:17pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723 "2017-02-01T17:17:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Alavi1412](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alavi1412/32/67721_2.png) [@Alavi1412](https://meta.discourse.org/u/Alavi1412)
#### Post date: [February 1, 2017, 5:17pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/1 "2017-02-01T17:17:00Z")

</div>

**Is there any way to find the current route of user?**

for example if **user is watching** homepage it return something like `homepage`.

or if **user is watching** a category with id of 52 (just an example) it returns `category 52` or something similar to this to distinguish where the user is.

(I want this for creating a very dynamic widget and it should provide different menu on each page)  
(and I don’t want to use `window.location.href` because url differ from each site to another and I want to create a widget for all discourse sites)

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [February 1, 2017, 6:40pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/2 "2017-02-01T18:40:23Z")

</div>

If you import `getOwner` you can do this:

```plaintext
const path = getOwner(this).lookup('controller:application').get('currentPath');

```

---

<div class="post-metadata">

### Author: ![Alavi1412](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alavi1412/32/67721_2.png) [@Alavi1412](https://meta.discourse.org/u/Alavi1412)
#### Post date: [February 1, 2017, 6:55pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/3 "2017-02-01T18:55:23Z")

</div>

thank you so much but this have some problem.  
for example when I open `http://localhost:3000/c/foodwaste/information` It showed `discovery.category` and it didn’t give any information about category

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [February 1, 2017, 7:03pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/4 "2017-02-01T19:03:57Z")

</div>

The current route is `discovery.category`, and the category is known as a dynamic segment. If you need to know information about the category, you can get it from the controller:

```plaintext
const category = getOwner(this).lookup('controller:discovery.category').get('model');

```

---

<div class="post-metadata">

### Author: ![duranmla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/duranmla/32/109295_2.png) [@duranmla](https://meta.discourse.org/u/duranmla)
#### Post date: [March 14, 2018, 3:57pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/5 "2018-03-14T15:57:33Z")

</div>

What is the advantage of this over `window.location.pathname`?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [March 14, 2018, 4:11pm UTC](https://meta.discourse.org/t/getting-current-user-route-and-path/56723/6 "2018-03-14T16:11:14Z")

</div>

It’s retrieving the actual category model so you can get more than just the name.

Additionally, relying on the path name assumes it’ll never change, like subfolder installs and such.
