switchPath
Advanced
switch case
for URLs, a small tool for routing in JavaScript
npm install switch-path
Usage
Basic usage:
const path value = ;// path is `/home/foo`// value is 456
Supports trailing slashes
const path value = ;// path is `/home/foo`// value is 456
Supports nested route configuration:
const path value = ;// path is `/home/foo`// value is 456
Supports base paths in nested route configurations
const path value = ;// path is `/home`// value is 456
Incomplete patterns will be optimistically matched:
const path value = ;// path is `/home`// value is 456
Optional not found pattern:
const path value = ;// path = '/home/33'// value = 'Route not found'
Match a route with :param
parameters and get the parameter value in a function:
const path value = ;// path is `/home/1736`// value is 'id is 1736'
Match a route with :param
parameters also inside nested configurations:
const path value = ;// path is `/home/1736`// value is 'id is 1736'
Match a route with :param
parameters base inside nested configurations:
const path value = ;// path is `/1736`// value is 'id is 1736'