kitbagjs / router

A type safe router for vuejs
https://router.kitbag.dev
MIT License
173 stars 4 forks source link

Serve app at subfolder? #245

Closed hongquan closed 1 month ago

hongquan commented 1 month ago

For example, we want our Vue app to run at /p/ URL. In vue-router, we achieve that by createWebHistory, but in @kitbag/router, I haven't found an equivalent.

stackoverfloweth commented 1 month ago

@hongquan, I think this is a good suggestion since the pattern is commonly used.

However, I also think we can solve for your use case rather simply unless I'm missing something that base option does in vue-router.

If you simply create a base route that acts as the parent to whatever base routes you currently have, this should achieve the same end goal.

// this route won't be navigable, will use `<RouterView />` as component by deafult
const baseRoute = createRoute({
  path: "/p/"
})

// routes supplied to router does not need to include `baseRoute` for this to work
const routes = [
  createRoute({
    parent: baseRoute,
    name: "foo",
    // actual path will be "/p/foo"
    path: "foo",
    ...
  })
] as const
hongquan commented 1 month ago

@stackoverfloweth Thanks.