PHPackages                             basecode/route - 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. basecode/route

ActiveLibrary[Framework](/categories/framework)

basecode/route
==============

Component route, componente para criação de projetos mvc com rotas.

2.1.0(4y ago)124MITPHPPHP &gt;=7.0

Since Jul 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/arthurthcoder/route)[ Packagist](https://packagist.org/packages/basecode/route)[ RSS](/packages/basecode-route/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (12)Used By (0)

**Route**
=========

[](#route)

[![route license](https://camo.githubusercontent.com/bc20a65fd584078f28e92cb9c2da39d112a28be2c42806427a7d80207050e695/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6172746875727468636f6465722f726f7574653f636f6c6f723d253233333243373534266c6f676f3d4d4954)](https://camo.githubusercontent.com/bc20a65fd584078f28e92cb9c2da39d112a28be2c42806427a7d80207050e695/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6172746875727468636f6465722f726f7574653f636f6c6f723d253233333243373534266c6f676f3d4d4954)[![GitHub tag (latest by date)](https://camo.githubusercontent.com/10bb0ff92c2fe4c32baac0248fe1dd31fb4f1cc967d8b17b81eea40395f5c633/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6172746875727468636f6465722f726f757465)](https://camo.githubusercontent.com/10bb0ff92c2fe4c32baac0248fe1dd31fb4f1cc967d8b17b81eea40395f5c633/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6172746875727468636f6465722f726f757465)

### What's the route ?

[](#whats-the-route-)

Summary: Route is a standalone component for creating routes in mvc systems.

Features
--------

[](#features)

- Creating quick routes.
- Creating routes with dynamic parameters.
- Creating routes of type \[ get | post | put | patch | delete \].
- Default route creation.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

You can install the route in your project with composer.

Just run the command below on your terminal:

```
composer require basecode/route
```

or in your composer.json require:

```
"basecode/route": "2.1.*"
```

Usage
-----

[](#usage)

After installing the route, it is very easy to use it, just instantiate a route object in your project's index and start creating your routes.

### Recommendation for using the route

[](#recommendation-for-using-the-route)

The recommendation is to have a .htaccess file that points the URI as parameter GET\[route\] to the index of your project, where the route will be.

Example **.htaccess** file:

```
RewriteEngine On
Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1
```

or you can pass the variable that receives the route as a parameter to the method execute, see the example below.

Example **index.php** file:

```
define("DS", DIRECTORY_SEPARATOR);
define("DOMAIN", "https://localhost/project");

require_once dirname(__DIR__).DS."vendor".DS."autoload.php";

use BaseCode\Route\Route;

/*
    domain_url [string] [required]
    separator_controller_method [string] [optional] [default] = ":"

    $route = new Route(domain_url, separator_controller_method);

    # EXAMPLE
    $route = new Route(DOMAIN, ":");

*/

$route = new Route(DOMAIN);

/*
    route [string] [required]
    route_action [string|function] [required]
    route_name [string] [optional]

    $route->get(route, route_action, route_name);
    $route->post(route, route_action, route_name);
    $route->put(route, route_action, route_name);
    $route->delete(route, route_action, route_name);

    action [string|function]
    $route->standard(action);

    # EXAMPLE
    $route->get("admin/login", function() {
        echo "ADMIN LOGIN";
    }, "admin.login");

*/

$route->get("/", function() {
    echo "HOME PAGE";
}, "home");

$route->namespace("Controllers\\Admin")->group("admin");

$route->get("/", "Controller:login", "admin.login");

// get route to namespace: Controllers\Admin\Controller - method: login

$route->execute();
/*
    or
    $route->execute("route"); // route is the name received by $_GET
*/
```

### Creating standard route

[](#creating-standard-route)

The standard route is used when the route requested via the url is not found.

Example **standard** route:

```
$route = new Route(DOMAIN);

$route->get("/", function() {
    echo "HOME PAGE";
}, "home");

$route->standard(function($error) {
    http_response_code($error["code"]);
    echo "ERROR: ".$error["message"]."";
});

$route->execute();
```

### Using the route method

[](#using-the-route-method)

The route method returns the route with the specified name or null if it is not found.

Example **route** method:

```
$route = new Route(DOMAIN);

$route->get("/", function() use ($route) {

    $link = $route->route("landing.page");
    echo "HOME PAGELanding";

}, "home");

$route->get("landing", function() use ($route) {

        $link = $route->route("home");
        echo "LANDING PAGEBack Home";

}, "landing.page");

$route->execute();
```

### Passing parameters to the route

[](#passing-parameters-to-the-route)

It is possible to define parameters for the routes, thus allowing to receive dynamic values.

Example **parameters** for route:

```
$route = new Route(DOMAIN);

$route->get("hello/{name}", function($data) {

    $name = $data["name"];
    echo "HELLO {$name}";

}, "hello.page");

$route->execute();
```

### Get url of current route

[](#get-url-of-current-route)

It is possible to get the url of the current route using the (current) method

Example of **current route**:

```
$route = new Route(DOMAIN);

$route->get("product/{id}", function() use ($route) {

    $current = $route->current();
    echo "ROUTE: {$current}";

}, "product.page");

$route->execute();
```

### Route redirection

[](#route-redirection)

It is possible to redirect routes using the (redirect) method.

Example of **redirect** :

```
$route = new Route(DOMAIN);

// REDIRECT OPTIONS

/* USING NAME

    ROUTES EXAMPLES (
        $route->get("/home", route_action, "page.home");
        $route->get("/product/{id}", route_action, "page.product");
    )

    $route->redirect("page.home"); // redirect to domain/home
    $route->redirect("page.product", ["id" => 10]); // redirect to domain/product/10
*/

/* USING URL
    $route->redirect("https://www.google.com"); // redirect to passed URL
*/

$route->group("admin");

$route->get("/login", function() {

    echo "ADMIN LOGIN";

}, "admin.login");

$route->get("/home", function() use ($route) {

    if (!isset($_SESSION["ADMIN_USER"])) {
        $route->redirect("admin.login");
    }

    echo "ADMIN HOME";

}, "admin.home");

$route->execute();
```

> To be continued...

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Every ~23 days

Recently: every ~51 days

Total

11

Last Release

1529d ago

Major Versions

1.2.2 → 2.0.02022-03-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d437710a031f683d0dab73ee70e428cc82f6bcee172cbcd30a7a99e679c2b98?d=identicon)[arthurthcoder](/maintainers/arthurthcoder)

---

Top Contributors

[![arthurthcoder](https://avatars.githubusercontent.com/u/84587643?v=4)](https://github.com/arthurthcoder "arthurthcoder (19 commits)")

---

Tags

routeBaseCodeThcoder

### Embed Badge

![Health badge](/badges/basecode-route/health.svg)

```
[![Health](https://phpackages.com/badges/basecode-route/health.svg)](https://phpackages.com/packages/basecode-route)
```

###  Alternatives

[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[izniburak/router

simple router class for php

23522.6k7](/packages/izniburak-router)[lesichkovm/laravel-advanced-route

Advanced route class for Laravel - restoring implicit controllers to the framework.

70140.7k1](/packages/lesichkovm-laravel-advanced-route)[ecoal95/php-router

Minimal routing library

271.0k1](/packages/ecoal95-php-router)[rosengate/exedra

Nestful route oriented PHP micro framework

142.0k1](/packages/rosengate-exedra)[developermarius/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

112.4k](/packages/developermarius-simple-router)

PHPackages © 2026

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