<p>From your Plugin class, add this code:</p>

<pre class="lang-php prettyprint-override"><code>use craft\events\RegisterUrlRulesEvent;
use craft\web\UrlManager;
use yii\base\Event;

// ...

class Plugin extends \craft\base\Plugin
{
    $hasCpSection = true;

    public function init()
    {
        // Register a custom CP route
        Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $e) {
            $e-&gt;rules['your/custom/uri'] = ['template' =&gt; 'plugin-handle/index'];
        });
    }

    public function getCpNavItem()
    {
        // Use the default name &amp; icon, but customize the URL
        $navItem = parent::getCpNavItem();
        $navItem['url'] = 'your/custom/uri';
        return $navItem;
    }

    // ...
}
</code></pre>

CC BY-SA 3.0
2017-12-07T16:54:54.360Z
2017-12-07T17:05:28.180Z
2017-12-07T17:05:28.180Z
Brandon Kelly
<p>Of course you can <a href="https://github.com/craftcms/docs/blob/master/en/updating-plugins.md#registercproutes" rel="nofollow noreferrer">Link</a></p>

<pre><code>Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) {
    $event-&gt;rules['whateveryoulike'] = ['template' =&gt; 'cocktails/_edit'];
    $event-&gt;rules['cocktails/&lt;widgetId:\d+&gt;'] = 'cocktails/edit-cocktail';
});
</code></pre>

<p>So the url <code>www.example.com/admin/whateveryoulike</code> redirects you to the template <code>cocktails/_edit</code>. You don't need to use the plugin-handle, you can overwrite everything but you have to make sure no other plugin overwrites your routes..</p>

CC BY-SA 3.0
2017-12-07T14:58:56.163Z
2017-12-07T16:56:02.420Z
2017-12-07T16:56:02.420Z
Robin Schambach
<p>Is it possible to use a custom route for your plugin's CP section, instead of <code>cpTrigger/plugin-handle</code>, or to direct <code>cpTrigger/plugin-handle</code> to a different template other than <code>plugin-handle/index.twig</code>?</p>

<plugin-development><control-panel><craft3>
Is it possible to set a new route for a plug-in CP section in Craft 3?
# Is it possible to set a new route for a plug-in CP section in Craft 3?

(Asked by: username_0 on 2017-12-07)

Is it possible to use a custom route for your plugin's CP section, instead of `cpTrigger/plugin-handle`, or to direct `cpTrigger/plugin-handle` to a different template other than `plugin-handle/index.twig`?

**Tags:** plugin-development, control-panel, craft3


---

## 2 answers

### Answer by username_1 on 2017-12-07. Score: 1 | Accepted answer

From your Plugin class, add this code:
use craft\events\RegisterUrlRulesEvent;
use craft\web\UrlManager;
use yii\base\Event;

// ...

class Plugin extends \craft\base\Plugin
{
    $hasCpSection = true;

    public function init()
    {
        // Register a custom CP route
        Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $e) {
            $e->rules['your/custom/uri'] = ['template' => 'plugin-handle/index'];
        });
    }

    public function getCpNavItem()
    {
        // Use the default name & icon, but customize the URL
        $navItem = parent::getCpNavItem();
        $navItem['url'] = 'your/custom/uri';
        return $navItem;
    }

    // ...
}


---

### Answer by username_2 on 2017-12-07. Score: 2

Of course you can Link
Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) {
    $event->rules['whateveryoulike'] = ['template' => 'cocktails/_edit'];
    $event->rules['cocktails/'] = 'cocktails/edit-cocktail';
});

So the url www.example.com/admin/whateveryoulike redirects you to the template cocktails/_edit. You don't need to use the plugin-handle, you can overwrite everything but you have to make sure no other plugin overwrites your routes..


---

