router5
  • Read Me
  • Introduction
    • Why router5?
    • Getting Started
    • Ecosystem
    • Core concepts
    • Transition phase
  • Guides
    • Defining routes
    • Path Syntax
    • Router options
    • Navigating
    • In the browser
    • Observing state
  • Integration
    • With React
    • With Redux
  • Advanced
    • Plugins
    • Middleware
    • Preventing navigation
    • Errors and redirections
    • Dependency injection
    • Loading async data
    • Universal routing
    • Listeners plugin
  • API Reference
  • Migration
    • Migrating from 7.x to 8.x
    • Migrating from 6.x to 7.x
    • Migrating from 5.x to 6.x
    • Migrating from 4.x to 5.x
    • Migrating from 3.x to 4.x
    • Migrating from 2.x to 3.x
    • Migrating from 1.x to 2.x
    • Migrating from 0.x to 1.x
Powered by GitBook
On this page
  • Defining parameters
  • Constrained parameters
  • Absolute nested paths
  1. Guides

Path Syntax

PreviousDefining routesNextRouter options

Last updated 6 years ago

router5 uses for parsing, matching and generating URLs

Defining parameters

Four parameter types are supported:

  • :param: url parameters

  • ;matrix: matrix parameters

  • *splat: for parameters spanning over multiple segments. Splat parameters are greedy and could swallow a

    large part of your URL. It is recommended to handle with care and to ONLY use on routes without children.

  • ?param1&param2 or ?:param1&:param2: query parameters

Constrained parameters

Url and matrix parameters can be constrained with a regular expression. Backslashes need to be escaped.

  • :param<\\d+> will match numbers only for parameter param

  • ;id<[a-fA-F0-9]{8}> will match 8 characters hexadecimal strings for parameter id

Constraints are also applied when building paths: when passing incorrect params to .navigate(), an error will be thrown.

Absolute nested paths

You can define absolute nested paths (not concatenated with their parent's paths). Note that absolute paths are not allowed if any parent of a node has parameters.

const router = createRouter([
    { name: 'admin', path: '/admin' },
    { name: 'admin.users', path: '~/users' }
]);

router.buildPath('admin.users'); // '/users'
path-parser