# Creating a route in a plugin

**URL:** https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407
**Category:** Support
**Created:** [2016年一月24日 20:52 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407 "2016-01-24T20:52:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![arrancscott](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arrancscott/32/50191_2.png) [@arrancscott](https://meta.discourse.org/u/arrancscott)
#### Post date: [2016年一月24日 20:52 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/1 "2016-01-24T20:52:56Z")

</div>

Hey guys,

I need a bit of help from someone familiar with creating routes in plugins.

I’ve created a plugin and have a route specified in my plugin.rb file like so:

```
register_asset 'javascripts/discourse/templates/user/route.hbs'

after_initialize do
 Discourse::Application.routes.append do
   get 'users/:username/route' => 'users#show', constraints: {username: USERNAME_ROUTE_FORMAT}
 end
end

```

I also have a ‘\*-route-map.js.es6’ file which declares this route like so:

```
export default function() {
   this.resource('user', function() {
   this.route('route', {path: 'route'});
 });
}`

```

I literally want to create a route like ‘/users/:username/route’ but none of what I’m doing seems to be working and I’m getting the default 404 page when I go to that URL.

I’ve looked at how a few plugins do it such as the tagging one and I seem to be doing everything correctly so I can’t figure out where I’m going wrong. Can someone help please?

---

<div class="post-metadata">

### Author: ![arrancscott](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arrancscott/32/50191_2.png) [@arrancscott](https://meta.discourse.org/u/arrancscott)
#### Post date: [2016年一月25日 20:46 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/2 "2016-01-25T20:46:17Z")

</div>

Fixed, after a few hours of head scratching.

```
export default {
 resource: 'user',
 path: 'users/:username',
 map() {
  this.route('route', { path: '/route' })
 }
}

```

Posted this incase another user stumbles across this post looking for an answer (which is exactly what I did).

---

<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: [2016年一月25日 21:01 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/3 "2016-01-25T21:01:54Z")

</div>

There is also a [tutorial here](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-5-admin-interfaces/31761) which shows how to create admin routes. It is preferable to create plugin routes in the admin section whenever possible.

---

<div class="post-metadata">

### Author: ![arrancscott](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arrancscott/32/50191_2.png) [@arrancscott](https://meta.discourse.org/u/arrancscott)
#### Post date: [2016年一月25日 21:47 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/4 "2016-01-25T21:47:44Z")

</div>

Yeah, I followed that but couldn’t figure out what I wanted to do from that tutorial.

Thanks!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2018年十二月12日 03:18 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/5 "2018-12-12T03:18:58Z")

</div>



---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [2018年十二月12日 07:18 UTC](https://meta.discourse.org/t/creating-a-route-in-a-plugin/38407/6 "2018-12-12T07:18:11Z")

</div>


