-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: construct correct pathname for isr from route with nested params (…
…#9470) * fix: constructor correct pathname for isr from route with nested params fixes #9459 * remove extraneous slashes * typo * remove logging --------- Co-authored-by: Rich Harris <git@rich-harris.dev>
- Loading branch information
1 parent
a243aa6
commit f427d47
Showing
7 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-vercel': patch | ||
--- | ||
|
||
fix: construct correct pathname for isr from route with nested params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { get_pathname } from '../utils.js'; | ||
|
||
/** | ||
* @param {import('@sveltejs/kit').RouteDefinition<any>['segments']} segments | ||
* @param {string} expected | ||
*/ | ||
function run_get_pathname_test(segments, expected) { | ||
const route = /** @type {import('@sveltejs/kit').RouteDefinition<any>} */ ({ segments }); | ||
assert.equal(get_pathname(route), expected); | ||
} | ||
|
||
test('get_pathname for simple route', () => { | ||
run_get_pathname_test([{ content: 'foo', dynamic: false, rest: false }], 'foo'); | ||
}); | ||
|
||
test('get_pathname for route with parameters', () => { | ||
run_get_pathname_test( | ||
[ | ||
{ content: 'foo', dynamic: false, rest: false }, | ||
{ content: '[bar]', dynamic: true, rest: false } | ||
], | ||
'foo/$1' | ||
); | ||
}); | ||
|
||
test('get_pathname for route with parameters within segment', () => { | ||
run_get_pathname_test( | ||
[ | ||
{ content: 'foo-[bar]', dynamic: true, rest: false }, | ||
{ content: '[baz]-buz', dynamic: true, rest: false } | ||
], | ||
'foo-$1/$2-buz' | ||
); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** @param {import("@sveltejs/kit").RouteDefinition<any>} route */ | ||
export function get_pathname(route) { | ||
let i = 1; | ||
|
||
return route.segments | ||
.map((segment) => { | ||
if (!segment.dynamic) { | ||
return segment.content; | ||
} | ||
|
||
const parts = segment.content.split(/\[(.+?)\](?!\])/); | ||
return parts | ||
.map((content, j) => { | ||
if (j % 2) { | ||
return `$${i++}`; | ||
} else { | ||
return content; | ||
} | ||
}) | ||
.join(''); | ||
}) | ||
.join('/'); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.