Releases: staltz/switch-path
Releases · staltz/switch-path
More corner cases supported
Supports trailing slashes
const {path, value} = switchPath('/home/foo/', {
'/bar': 123,
'/home/foo': 456,
});
// path is `/home/foo`
// value is 456
Supports base paths in nested route configurations
const {path, value} = switchPath('/home', {
'/bar': 123,
'/home': {
'/': 456,
'/foo': 789
}
});
// path is `/home`
// value is 456
Optional not found pattern:
const {path, value} = switchPath('/home/33', {
'/': 123,
'books': {
'/': 456,
'/:id': 789
},
'*': 'Route not found'
});
// path = '/home/33'
// value = 'Route not found'
Match a route with :param
parameters base inside nested configurations:
const {path, value} = switchPath('/1736', {
'/bar': 123,
'/:id': {
'/': id => `id is ${id}`,
'/home': 789
}
});
// path is `/1736`
// value is 'id is 1736'