mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[remix] Fix support for optional path params (#9590)
Changes the way that routes with optional params are stored on Vercel to not use `?` in the name, because it's not possible to have a route destination with a `?` that's pointing to a function. So instead of the function with a name such as `:lang?`, it will be stored on Vercel with a name like `(:lang)`, which can be routed to.
This commit is contained in:
@@ -2,17 +2,18 @@ import { getRegExpFromPath } from '../src/utils';
|
||||
|
||||
describe('getRegExpFromPath()', () => {
|
||||
describe('paths without parameters', () => {
|
||||
it.each([{ path: 'index' }, { path: 'api/hello' }, { path: 'projects' }])(
|
||||
'should return `false` for "$path"',
|
||||
({ path }) => {
|
||||
expect(getRegExpFromPath(path)).toEqual(false);
|
||||
}
|
||||
);
|
||||
it.each([
|
||||
{ path: '/index' },
|
||||
{ path: '/api/hello' },
|
||||
{ path: '/projects' },
|
||||
])('should return `false` for "$path"', ({ path }) => {
|
||||
expect(getRegExpFromPath(path)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe.each([
|
||||
{
|
||||
path: '*',
|
||||
path: '/:params+',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
@@ -37,7 +38,7 @@ describe('getRegExpFromPath()', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'projects/*',
|
||||
path: '/projects/:params+',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
@@ -58,7 +59,7 @@ describe('getRegExpFromPath()', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
path: ':foo',
|
||||
path: '/:foo',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
@@ -79,7 +80,7 @@ describe('getRegExpFromPath()', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'blog/:id/edit',
|
||||
path: '/blog/:id/edit',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
@@ -107,6 +108,65 @@ describe('getRegExpFromPath()', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/:lang?',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/en',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/en/other',
|
||||
expected: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/:lang?/other',
|
||||
urls: [
|
||||
{
|
||||
url: '/other',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/en/other',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/another',
|
||||
expected: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/:lang?/:pid',
|
||||
urls: [
|
||||
{
|
||||
url: '/123',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/en/123',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/en/foo/bar',
|
||||
expected: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
])('with path "$path"', ({ path, urls }) => {
|
||||
const re = getRegExpFromPath(path) as RegExp;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user