Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/pages/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions packages/urban-core/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> = import.meta.glob('/src/pages/[**/a-z[]*.{tsx,jsx}', { eager: true });
const PRESERVED: Record<string, any> = import.meta.glob('/src/pages/(_app|404|_document).{tsx,jsx}', { eager: true });

console.log(PRESERVED)
ReactDOM.createRoot(document.getElementById('root')!).render(
Expand Down
3 changes: 3 additions & 0 deletions packages/urban-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/urban-router/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Router } from './router'
export { Router as UrbanRouter } from './router'
38 changes: 19 additions & 19 deletions packages/urban-router/src/router.tsx
Original file line number Diff line number Diff line change
@@ -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<string, any>, PRESERVED: Record<string, any>}) => {

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
Expand Down