---
title: Routers
---

# Routers

<div class="documentation__toc"></div>

## Introduction

Entry routers assist in binding `named routes` to stream entries. This makes it much easier to override routing by simply defining another route with the same name.

The basic idea is as that instead of something like this in your code:

```php
echo "articles/{$article->category->slug}/view/{$article->slug}";
```

```twig
{{ url('articles/' ~ category.slug ~ '/view/' ~ article.slug) }}
```

You can rely on entry routing to simply do this:

```php
$article->route('view');
```

```twig
{{ article.route('view') }}
```


## Basic Usage

To get started with entry routing you must first define your routes with a specific naming pattern.

We'll use an [AddonServiceProvider](../core-concepts/service-provider) for routing in this example.

```php
protected $routes = [
    "posts/{slug}" => [
        'as'   => 'anomaly.module.posts::posts.view',
        'uses' => 'Anomaly\PostsModule\Http\Controller\PostsController@view',
    ],
];
```

Note the above route is named `anomaly.module.posts::posts.view`. This can be broken down into the addons `namespace`, then the entry's `stream` slug, and lastly the route `action`.

```bash
{namespace}::{stream}.{action}
```

By calling `route($action)` on an entry model the Streams Platform will lookup what addon the model belongs to and find use it's stream slug and action to return the route path.

### More Examples

```php
$article->route('view');

$article->route('categories.index');

// Equivalent long syntax.
$article->getRouter()->make('view');

$article->getRouter()->make('categories.index');
```

```twig
{{ article.route('view') }}

{{ article.route('categories.index') }}
```
