Routes loader module for Webpack. Converts path strings into regular expressions.

Usage no npm install needed!

<script type="module">
  import pathToRegexpLoader from '';


path-to-regexp loader for Webpack

How to Install

npm install path-to-regexp-loader --save-dev

How to Use

Given a routes.json file that may look like this:

  { "path": "/tasks", "component": "TodoList" },
  { "path": "/tasks/:id(\\d+)", "component": "TodoItem" }

You can parse it by using path-to-regexp-loader:

var routes = require('!!path-to-regexp-loader!./routes.json');
// => returns routes.json content as JSON parsed object
    path: '/tasks',
    pattern: /^\/tasks(?:\/(?=$))?$/i,
    keys: [],
    component: 'TodoList'
    path: '/tasks/:id(\\d+)',
    pattern: /^\/tasks\/((?:\d+))(?:\/(?=$))?$/i,
    keys: [
        name: 'id',
        prefix: '/',
        delimiter: '/',
        optional: false,
        repeat: false,
        partial: false,
        asterisk: false,
        pattern: '\\d+'
    component: 'TodoItem'

Related Projects


MIT © 2016-present Konstantin Tarkus (@koistya)