diff --git a/.changeset/ten-frogs-smoke.md b/.changeset/ten-frogs-smoke.md new file mode 100644 index 0000000000..6a553ecfe9 --- /dev/null +++ b/.changeset/ten-frogs-smoke.md @@ -0,0 +1,5 @@ +--- +"@ima/core": patch +--- + +Backport fix from `next` - for missing optional parameters in static router that are evaluated as 'undefined' instead of undefined. diff --git a/packages/core/src/router/StaticRoute.ts b/packages/core/src/router/StaticRoute.ts index 07af3702a2..bff74c7f09 100644 --- a/packages/core/src/router/StaticRoute.ts +++ b/packages/core/src/router/StaticRoute.ts @@ -508,7 +508,7 @@ export default class StaticRoute extends AbstractRoute { if (currentCoreName) { const value = AbstractRoute.decodeURIParameter(rawValue) as string; - parameters[currentCoreName] = value; + parameters[currentCoreName] = rawValue ? value : rawValue; } } diff --git a/packages/core/src/router/__tests__/StaticRouteSpec.ts b/packages/core/src/router/__tests__/StaticRouteSpec.ts index 64f27ae133..56bb87dbad 100644 --- a/packages/core/src/router/__tests__/StaticRouteSpec.ts +++ b/packages/core/src/router/__tests__/StaticRouteSpec.ts @@ -806,6 +806,11 @@ describe('ima.core.router.StaticRoute', function () { path: '/something/param1/user1', params: {}, }, + { + pathExpression: '/test/:?param1/:?param2', + path: '/test/xxx', + params: { param1: 'xxx', param2: undefined }, + }, ].forEach(value => { it(value.pathExpression, function () { const localStaticRoute = new StaticRoute(