PHPackages                             admirhodzic/nano-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. admirhodzic/nano-router

ActiveLibrary[Framework](/categories/framework)

admirhodzic/nano-router
=======================

Nano router for PHP apps

1.0.0(6y ago)1101MITPHPPHP &gt;=5.4.0CI failing

Since Nov 1Pushed 6y ago1 watchersCompare

[ Source](https://github.com/admirhodzic/NanoRouter)[ Packagist](https://packagist.org/packages/admirhodzic/nano-router)[ RSS](/packages/admirhodzic-nano-router/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (2)Used By (0)

NanoRouter
==========

[](#nanorouter)

Nano-size router for PHP apps in just 20 lines of code.

Install
=======

[](#install)

```
composer require admirhodzic/nano-router

```

Usage
=====

[](#usage)

```
use admirhodzic\NanoRouter\NanoRouter;
// ...
$response = NanoRouter::run([
                //options...
            ]);

```

When request URL is **/posts/update/123?param2=abc**, this code will invoke a class with name PostController and call method **actionUpdate** with $id parameter set to '123' and 'param2' set to 'abc', if param2 is not set, default value is used. "id" parameter is mandatory.

```
class PostController{
    public action actionUpdate($id, $param2=''){ ... }
}

```

If URL doesn't contain controller or action name, defaults will be used. By default, 'SiteController' and 'actionIndex' method. To specify separate methods for different HTTP methods, just add a function with method name instead of 'action':

```
public function getPosts() { ... }
public function postPosts() { ... }
public function actionPosts() { ... }

```

This way, for GET request, 'getPosts' function will be called, for POST request, 'postPosts' function will be called, and 'actionPosts' will be called for all other request methods.

Options
=======

[](#options)

```
'default_controller'=>'site',
'default_action'=>'index',
'Controller'=>'Controller', //suffix of controller class name
'controller_namespace'=>'app\Controllers',
'routes'=>[
    //...custom routes. eg:

    '/login'=>'site/login',

    ///////////////       value is new URI string or a function which receives preg matches and returns a string

    'r1/a1(/(?[0-9]*))?'=>function ($p) {  ///////////// this matches r1/ar with optional numeric id
            //function receives extracted parameters and returns new // URI
            return isset($p['id']) ? ('site/other/'.$p['id']) : 'site/index';
        },

    ///////////////       routes order must be from most specific to general routes
]

```

License
=======

[](#license)

MIT

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2384d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/987d65043c0f504a4eefa9ba128d6f0af9991d5579485a7ae71402ff6765518d?d=identicon)[admirhodzic](/maintainers/admirhodzic)

---

Top Contributors

[![admirhodzic](https://avatars.githubusercontent.com/u/1506452?v=4)](https://github.com/admirhodzic "admirhodzic (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/admirhodzic-nano-router/health.svg)

```
[![Health](https://phpackages.com/badges/admirhodzic-nano-router/health.svg)](https://phpackages.com/packages/admirhodzic-nano-router)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
