Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named wildcard routes aren't working #338

Open
claydiffrient opened this issue Dec 4, 2015 · 2 comments
Open

Named wildcard routes aren't working #338

claydiffrient opened this issue Dec 4, 2015 · 2 comments
Labels

Comments

@claydiffrient
Copy link

It seems that named wildcard routes as described in the documentation aren't working as expected.

I wrote this test, and it fails consistently.

it('should populate named wildcard params', function (done) {
  page('/blog/post/:path(*)', function (ctx) {
    expect(ctx.params.path).to.equal('/assets/images/image.png');
  });

  page('/blog/post/assets/images/image.png');
});

The error that it throws is:

SyntaxError: Invalid regular expression: /^\/blog\/post\/(*)(?:\/(?=$))?$/: Nothing to repeat
      at new RegExp (native)
      at tokensToRegExp (node_modules/path-to-regexp/index.js:356:10)
      at stringToRegexp (node_modules/path-to-regexp/index.js:283:12)
      at pathToRegexp (node_modules/path-to-regexp/index.js:389:10)
      at new Route (index.js:451:19)
      at page (index.js:93:19)
      at Context.<anonymous> (test/tests.js:348:11)

I'm not super familiar with why this is happening. I'll put in a PR containing the failing test. If I get some time to investigate and look into it more I can fix it.

claydiffrient added a commit to claydiffrient/page.js that referenced this issue Dec 4, 2015
@woodlandhunter
Copy link
Contributor

It seems this is due to the changes in path-to-regexp. An asterisk by itself is supported (e.g. /some/*) as a special case, but not as part of a named group. The docs should likely be fixed to reflect this.

You can use '/blog/post/:path(.*)'

See pillarjs/path-to-regexp#37 (comment)

@matthewp
Copy link
Collaborator

Yep, we should update the documentation.

@matthewp matthewp added the docs label Jan 13, 2018
pR0Ps added a commit to pR0Ps/page.js that referenced this issue Mar 18, 2020
The docs were updated in the README by visionmedia#506, but the gh-pages site is still incorrect.

Fixes visionmedia#338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants