Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to generate a typesafe route file? #36

Closed
rainmanhhh opened this issue Apr 15, 2021 · 1 comment
Closed

Is it possible to generate a typesafe route file? #36

rainmanhhh opened this issue Apr 15, 2021 · 1 comment

Comments

@rainmanhhh
Copy link

add a script in package.json

"scripts": {
  "generate-routes": "vite-plugin-pages generate"
}

everytime run the generate command, it recreates the route file (routes.ts)

export const routes = {
  index: '#/',
  foo: {
    index: '#/foo',
    all: (p: unknown) => `#/foo/${p}`,
    bar: '#/foo/bar'
  }
}

then routing can be

import {routes} from './routes'

const Com = <div onClick={() =>history.push(routes.foo.index)}>go to foo</div>
@hannoeru
Copy link
Owner

I think use onClientGenerated hooks to generate a custom client code, with this feature: vuejs/router#872 can get typescript supported for route names.

@hannoeru hannoeru closed this as completed Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants