feat: INIT PROJECT.
This commit is contained in:
69
src/routes.tsx
Normal file
69
src/routes.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ApolloClient } from "@apollo/client";
|
||||
import { prepareRoutes } from "@curi/router";
|
||||
import { omit } from 'ramda';
|
||||
import { ARTICLE } from "./articles";
|
||||
import { Article } from './generated/graphql';
|
||||
|
||||
export default prepareRoutes([
|
||||
{
|
||||
name: "dashboard",
|
||||
path: "",
|
||||
respond() {
|
||||
return { body: () => <div>DashBoard</div> };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "create-article",
|
||||
path: "articles/create",
|
||||
resolve() {
|
||||
const body = import(
|
||||
/* webpackChunkName: "article-editor" */ "./articles"
|
||||
).then((m) => m.ArticleEditor);
|
||||
return body;
|
||||
},
|
||||
respond({ resolved }) {
|
||||
return { body: resolved };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "modify-article",
|
||||
path: "articles/:id",
|
||||
async resolve(matched, { client }: { client: ApolloClient<any> }) {
|
||||
const [ArticleEditor, result] = await Promise.all([
|
||||
import(/* webpackChunkName: "article-editor" */ "./articles").then(
|
||||
(m) => m.ArticleEditor
|
||||
),
|
||||
client.query<{article: Article}, { id: string }>({
|
||||
query: ARTICLE,
|
||||
variables: { id: matched!.params.id },
|
||||
}),
|
||||
]);
|
||||
console.log(ArticleEditor, result);
|
||||
return () => (
|
||||
<ArticleEditor article={omit(["__typename"], result.data.article)} />
|
||||
);
|
||||
},
|
||||
respond({ resolved }) {
|
||||
return { body: resolved };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "articles",
|
||||
path: "articles",
|
||||
resolve() {
|
||||
return import(/* webpackChunkName: "articles" */ "./articles").then(
|
||||
(m) => m.ArticleIndex
|
||||
);
|
||||
},
|
||||
respond({ resolved }) {
|
||||
return { body: resolved };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "tags",
|
||||
path: "tags",
|
||||
respond() {
|
||||
return { body: () => <div>Tags</div> };
|
||||
},
|
||||
},
|
||||
]);
|
||||
Reference in New Issue
Block a user