![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
generouted
Advanced tools
Generated file-based routes for Vite
I enjoyed working with file-based routing since started using it with Next.js. After trying the same concept with Vite, I started a series of blog posts covering client-side file-based routing with React Router inspired by Next.js. Later, in the last two posts, I replaced React Router with React Location to add more features like data loaders and nested layouts that are inspired by Remix. The final version covered in the blog posts is now published as generouted
, see all the available features below.
generouted
is only one source code file, with no dependencies or build step. It uses Vite's glob import API to list the modules within src/pages
directory to be used as React Location's routes.
src/pages
directoryIn case you don't have a Vite project with React and TypeScript, check Vite documentation to start a new project.
pnpm add generouted @tanstack/react-location
// src/main.tsx
import { createRoot } from 'react-dom/client'
import { Routes } from 'generouted/react-location'
const container = document.getElementById('app')!
createRoot(container).render(<Routes />)
pnpm add generouted react-router-dom
// src/main.tsx
import { createRoot } from 'react-dom/client'
import { Routes } from 'generouted/react-router'
const container = document.getElementById('app')!
createRoot(container).render(<Routes />)
If you're using Solid, check out their getting started guide to start a new project.
pnpm add generouted @solidjs/router
// src/main.tsx
import { render } from 'solid-js/web'
import { Routes } from 'generouted/solid-router'
render(Routes, document.getElementById('app')!)
Add the home page by creating a new file src/pages/index.tsx
→ /
, then export a default component:
export default function Home() {
return <h1>Home</h1>
}
See more about generouted
routing conventions below.
src/pages
directory.jsx
and .tsx
extensionsdefault
exportsrc/pages/_app.tsx
(optional)src/pages/404.tsx
(optional)Link
or A
componentLoader
from a page: export const Loader = async () => ({...})
Action
from a page: export const Action = async () => ({...})
_layout.tsx
file inside of the nested directory<Outlet />
component to render its childrensrc/pages/index.tsx
→ /
src/pages/posts/index.tsx
→ /posts
src/pages/posts/2022/index.tsx
→ /posts/2022
src/pages/posts/2022/resolutions.tsx
→ /posts/2022/resolutions
src/pages/posts/[slug].tsx
→ /posts/:slug
src/pages/posts/[slug]/tags.tsx
→ /posts/:slug/tags
src/pages/posts/[...all].tsx
→ /posts/*
Add a layout for all the routes within src/pages/posts
directory by adding src/pages/posts.tsx
or src/pages/posts/_layout.tsx
:
src/pages/posts.tsx
or src/pages/posts/_layout.tsx
src/pages/posts/index.tsx
→ /posts
src/pages/posts/2022/index.tsx
→ /posts/2022
src/pages/posts/[slug].tsx
→ /posts/:slug
Add a file outside of the directory with a nested layout, then name the file by adding a dot between each segment, it will be converted to forward slashes:
src/pages/posts.nested.as.url.not.layout.tsx
→ /posts/nested/as/url/not/layout
Any directory or a file starts with _
will be ignored
src/pages/_ignored.tsx
src/pages/posts/_components/button.tsx
src/pages/posts/_components/link.tsx
<Routes />
<Routes />
component accepts all React Location's RouterProps
except children
, location
and routes
props.
<Routes />
No available props.
<Routes />
No available props.
MIT
FAQs
Generated client-side file-based routes for Vite
The npm package generouted receives a total of 13,674 weekly downloads. As such, generouted popularity was classified as popular.
We found that generouted demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.