Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Typescript suggestions based on router configuration #2308

@rsmple

Description

@rsmple

What problem is this solving

Working with vue-router on different projects can be difficult because of the complicated route structure. It is not obvious which routes exist in the current configuration and what parameters they require (before you get an error at runtime). Verifying route locations becomes even more difficult when the router's configuration is spread across many files.

This feature should help to create and validate route locations across the project without much effort.

Proposed solution

Actually it is already possible to enable such TypeScript suggestions by declaring all router records with as const satisfies RouteRecordRaw[] and processing the result type. Here I wrote an article on how to implement this in Vue project. But this approach overrides internal interfaces and may noy be reliable enough. I think it is possible to implement this on the vue-router side, and that would work even better.

I would also like to suggest generic syntax for useRoute():

type RouteName // all existing route names

...

const route = useRoute<RouteName.SOME_ROUTE>() // route location, based on router record for route with name RouteName.SOME_ROUTE

This could also be done using the suggested router record processing.

Describe alternatives you've considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions