Skip to content

Commit

Permalink
chore(flat-routes): add support for optional and escape route segments
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Dec 20, 2022
1 parent 909b2d2 commit 7e579db
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 235 deletions.
13 changes: 11 additions & 2 deletions packages/remix-dev/__tests__/flat-routes-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createRoutePath } from "../config/flat-routes";
import {
createRoutePath,
getRouteSegments,
isIndexRoute,
} from "../config/flat-routes";

describe("createRoutePath", () => {
describe("creates proper route paths", () => {
Expand All @@ -10,6 +14,7 @@ describe("createRoutePath", () => {
["_auth", undefined],
["_landing.about", "about"],
["_landing._index", undefined],
["_landing.index", "index"],
["_landing", undefined],
["app.calendar.$day", "app/calendar/:day"],
["app.calendar._index", "app/calendar"],
Expand Down Expand Up @@ -94,7 +99,11 @@ describe("createRoutePath", () => {

for (let [input, expected] of tests) {
it(`"${input}" -> "${expected}"`, () => {
expect(createRoutePath(input)).toBe(expected);
let segments = getRouteSegments(input);
let index = isIndexRoute(input);
let result = createRoutePath(segments, index);
let expectedPath = expected === undefined ? undefined : "/" + expected;
expect(result).toBe(expectedPath);
});
}
});
Expand Down

0 comments on commit 7e579db

Please sign in to comment.