Skip to content

Commit

Permalink
Add dynamic import.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwjohnston committed Nov 19, 2023
1 parent 06f7c6d commit cbd1079
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/json/bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"one": "two"
}
3 changes: 3 additions & 0 deletions app/json/foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
16 changes: 16 additions & 0 deletions app/routes/$.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LoaderArgs } from "@remix-run/node"

export const loader = async (loaderInput: LoaderArgs) => {

const pathname = loaderInput.params["*"];
const result = await import(`../app/json/${pathname}.json`);


return result;
}

export default function () {


return <div>Whatever</div>
}
6 changes: 5 additions & 1 deletion app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { V2_MetaFunction } from "@remix-run/node";
import type { LoaderFunction, V2_MetaFunction } from "@remix-run/node";

export const meta: V2_MetaFunction = () => {
return [
Expand All @@ -7,6 +7,10 @@ export const meta: V2_MetaFunction = () => {
];
};

export const loader : LoaderFunction = async (args) => {
return null;
}

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "ES2019",
"module": "ESNext",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit cbd1079

Please sign in to comment.