#Rendering pages with custom slugs with slashes

2 messages · Page 1 of 1 (latest)

steep fractal
#

I was following the content collection documentation creating an example blog collection, defining the schema, and building static output with a [slug].astro file (Astro ^2.0.5, Mac, Node 16.14.2). Nothing special, mostly copying the documentation examples.

Everything rendered fine, except the one page with a custom slug (mentioned in the custom slug section), that included slashes. I tried leading slashes, trailing slashes, no slashes, in quotes, and moving the mdx file into a physical folder, but it failed each time.

Now, I’m wondering, what am I doing wrong?

The error message during npm run build is error Expected "slug" to match "[^\/#\?]+?", but got "my-custom-slug/supports/slashes" and the module path-to-regexp is throwing the error.

Full error output:

generating static routes
▶ src/pages/index.astro
  └─ /index.html (+15ms)
▶ src/pages/posts/[slug].astro
 error   Expected "slug" to match "[^\/#\?]+?", but got "my-custom-slug/supports/slashes"
  File:
    /Users/user/project/node_modules/path-to-regexp/dist/index.js:229:27
  Code:
    228 | if (validate && !matches[i].test(segment)) {
  > 229 |    throw new TypeError("Expected \"".concat(token.name, "\" to match \"").concat(token.pattern, "\", but got \"").concat(segment, "\""));
        |                                                                                                ^
    230 | }
hot grove