vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.04k stars 342 forks source link

Single Route File #341

Open brillout opened 2 years ago

brillout commented 2 years ago

Description

Being able to define the entire routing of the app in a single file.

// vike.config.h.ts

import type { Config } from 'vike/types'
import LandingPage from './pages/LandingPage.js'
import ProductListPage from './pages/ProductListPage.js'
import ProductPage from './pages/ProductPage.js'

export default {
  pages: [
    '/': {
      Page: LandingPage
    },
    '/product/@id': {
      Page: ProductPage
    },
    '/products': {
      Page: ProductListPage
    },
    // ...
  ]
} satisfies Config

If you want this, feel free to write a comment down below explaining why. The more we know why users want this, the better we can prioritize accordingly.

brillout commented 1 year ago

@doeixd You're right and that's the plan: https://vite-plugin-ssr.com/extends. (The rudimentary Single Route File implementation I mentioned earlier needed for the V1 design is actually precisely for enabling extensions to define pages.)

redbar0n commented 12 months ago

The ideal, imho, would be to have:

Thumbs up or heart if you like or love this ideal.

Update: Another thing I thought of is that it would be very nice to have the Vike code for parsing the filesystem routes available in a file (not buried deep within some framework code). So you could easily override it if you wanted to parse the filesystem routes differently (if you wanted a different project folder structure for instance).

brillout commented 8 months ago

@redbar0n

Each + file can live in a different environment which was a primary motivation for the V1 design; some of your ideas aren't implementable without code extraction (wich I believe to be an anti-pattern).

As for increased flexibility around Filesystem Routing I agree that'd be nice, but it isn't a priority at the moment. That said, I'm happy to revisit prioritisation upon blockers and/or sponsoring.

brillout commented 8 months ago

Latest design for defining all routes in a single file: https://github.com/vikejs/vike/issues/341#issue-1274652261.

redbar0n commented 8 months ago

some of your ideas aren't implementable without code extraction

I presume you mean «Code Extraction: The act of separating the code and creating server and client code bundles». But doesn’t Vike already do this to an extent?

If the problem with having all routes in a single file is that client side routing and server side routing would need to be extracted from that file, what about 2 files: a single route file for the client, and a single route file for the server? Could make it clearer. E.g. So if you want to SSR a particular page you’d move it to the single route file for the server.

brillout commented 8 months ago

@redbar0n I'm afraid it isn't that simple. In general, design needs an holistic understanding of a lot of problems at once. I'd be happy to elaborate but that would require 2-3 pages of text. As you can imagine, prioritization is crucial for Vike to grow.

That said, it's paramount that users communicate their pain points and what they try to achieve (the goals), and I'm more than happy to hear (critical) feedback here. The resulting design (how to achieve the goals) is a work that only Vike maintainers can do.