From 7243627be82d7c586646f26f5965e777cdc3a567 Mon Sep 17 00:00:00 2001 From: Vareen Agunda Date: Mon, 20 May 2024 21:46:08 +0300 Subject: [PATCH 1/2] Fix broken markdown links in docs --- docs/pages/introduction.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/pages/introduction.mdx b/docs/pages/introduction.mdx index e0f00eb..12b4650 100644 --- a/docs/pages/introduction.mdx +++ b/docs/pages/introduction.mdx @@ -8,11 +8,11 @@ To Note: The project is currently in development and is subject to change. ## Table of Contents -- [UI Package](UI/components) +- [UI Package](ui/components.mdx) -- [File-Based Routing (FBR)](routing) +- [File-Based Routing (FBR)](routing.mdx) -- [Signals](signals) +- [Signals](signals.mdx) ## UI Package From aac1b8c63b8be03fe621ee93093ce9f3a32a6c0a Mon Sep 17 00:00:00 2001 From: Vareen Agunda Date: Tue, 21 May 2024 07:07:02 +0300 Subject: [PATCH 2/2] Fix urban-router import bug --- packages/urban-core/src/main.tsx | 4 +-- packages/urban-router/package.json | 3 +++ packages/urban-router/src/index.ts | 2 +- packages/urban-router/src/router.tsx | 38 ++++++++++++++-------------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/urban-core/src/main.tsx b/packages/urban-core/src/main.tsx index 6efecc3..387292d 100644 --- a/packages/urban-core/src/main.tsx +++ b/packages/urban-core/src/main.tsx @@ -6,8 +6,8 @@ import { BrowserRouter } from 'react-router-dom'; import { UrbanRouter } from 'urban-router' // TODO: Find a way to export a glob mechanism from the router package -const Routes = import.meta.glob('/src/pages/[**/a-z[]*.{tsx,jsx}', { eager: true }); -const PRESERVED = import.meta.glob('/src/pages/(_app|404|_document).{tsx,jsx}', { eager: true }); +const Routes: Record = import.meta.glob('/src/pages/[**/a-z[]*.{tsx,jsx}', { eager: true }); +const PRESERVED: Record = import.meta.glob('/src/pages/(_app|404|_document).{tsx,jsx}', { eager: true }); console.log(PRESERVED) ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/packages/urban-router/package.json b/packages/urban-router/package.json index 1e1d2b4..651f4bd 100644 --- a/packages/urban-router/package.json +++ b/packages/urban-router/package.json @@ -12,6 +12,9 @@ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, + "exports": { + ".": "./src/index.ts" + }, "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/packages/urban-router/src/index.ts b/packages/urban-router/src/index.ts index 80ddfec..a6aad8f 100644 --- a/packages/urban-router/src/index.ts +++ b/packages/urban-router/src/index.ts @@ -1 +1 @@ -export { Router } from './router' \ No newline at end of file +export { Router as UrbanRouter } from './router' \ No newline at end of file diff --git a/packages/urban-router/src/router.tsx b/packages/urban-router/src/router.tsx index f45435d..3ec8f01 100644 --- a/packages/urban-router/src/router.tsx +++ b/packages/urban-router/src/router.tsx @@ -1,32 +1,32 @@ import { Fragment, Suspense } from 'react'; import { Routes, Route } from 'react-router-dom'; -const ROUTES = import.meta.glob('/src/pages/**/[a-z[]*.{tsx,jsx}', { eager: true }); +export const Router = ({ ROUTES, PRESERVED } : {ROUTES: Record, PRESERVED: Record}) => { -console.log("Routes:::", ROUTES); -// Add preserved routes like _app.tsx and 404.tsx. -// TODO: add the default routes to the template, and write docs on the same. + console.log("Routes:::", ROUTES); -const PRESERVED = import.meta.glob('/src/pages/(_app|404).{tsx,jsx}', { eager: true }); + // Add preserved routes like _app.tsx and 404.tsx. + // TODO: add the default routes to the template, and write docs on the same. -const routes = Object.keys(ROUTES).map((route) => { - const path = route - .replace(/\/src\/pages|index|\.tsx$/g, '') - .replace(/\[\.{3}.+\]/, '*') - .replace(/\[(.+)\]/, ':$1'); - // @ts-ignore - return { path, component: ROUTES[route].default }; -}); + const routes = Object.keys(ROUTES).map((route) => { + const path = route + .replace(/\/src\/pages|index|\.tsx$/g, '') + .replace(/\[\.{3}.+\]/, '*') + .replace(/\[(.+)\]/, ':$1'); + + // @ts-ignore + return { path, component: ROUTES[route].default }; + }); + + const preserved = Object.keys(PRESERVED).reduce((preserved, file) => { + const key = file.replace(/\/src\/pages\/|\.tsx$/g, ''); + // @ts-ignore + return { ...preserved, [key]: PRESERVED[file].default }; + }, {}); -const preserved = Object.keys(PRESERVED).reduce((preserved, file) => { - const key = file.replace(/\/src\/pages\/|\.tsx$/g, ''); - // @ts-ignore - return { ...preserved, [key]: PRESERVED[file].default }; -}, {}); -export const Router = () => { console.log(routes); // Sorry for the weak types. I'm still learning TS. // @ts-ignore