Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Allow for options to be passed to UrlPattern #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import yourReducer from './your-app';
// Useful for page titles and other route-specific data.

// Uses https://github.com/snd/url-pattern for URL matching
// and parameter extraction.
// and parameter extraction. Options for 'url-pattern' can be set in patternOptions
const routes = {
'/messages': {
title: 'Message'
Expand All @@ -64,7 +64,8 @@ const routes = {
'/bio': {
title: 'Biographies',
'/:name': {
title: 'Biography for:'
title: 'Biography for:',
patternOptions: {segmentValueCharset: 'a-zA-Z_'},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default (routes: Object) => {
.reverse()
.map(route => ({
route,
pattern: new UrlPattern(route),
pattern: new UrlPattern(route, routes[route].patternOptions || {}),
result: routes[route]
}));

Expand Down
4 changes: 4 additions & 0 deletions test/test-util/fixtures/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default flattenRoutes({
'/home/:spookyparam': {
name: '3spooky5me'
},
'/home/email/:customparam': {
name: 'custom',
patternOptions: { segmentValueCharset: 'a-zA-Z0-9-_~ %@.' }
},
'/': {
'/oh': {
name: 'oh',
Expand Down
10 changes: 10 additions & 0 deletions test/util/create-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,15 @@ describe('createMatcher', () => {
name: '3spooky5me'
}
});

expect(matchRoute('/home/email/[email protected]')).to.deep.equal({
route: '/home/email/:customparam',
params: {
customparam: '[email protected]'
},
result: {
name: 'custom'
}
});
});
});