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

feat(types): RouterConfig for multiple components (#3217) #3218

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions types/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,30 @@ export interface PathToRegexpOptions {
end?: boolean
}

export interface RouteConfig {
interface _RouteConfigBase {
path: string
name?: string
component?: Component
components?: Dictionary<Component>
redirect?: RedirectOption
alias?: string | string[]
children?: RouteConfig[]
meta?: any
beforeEnter?: NavigationGuard
props?: boolean | Object | RoutePropsFunction
caseSensitive?: boolean
pathToRegexpOptions?: PathToRegexpOptions
}

interface RouteConfigSingleView extends _RouteConfigBase {
component?: Component
props?: boolean | Object | RoutePropsFunction
}

interface RouteConfigMultipleViews extends _RouteConfigBase {
components?: Dictionary<Component>
posva marked this conversation as resolved.
Show resolved Hide resolved
children?: RouteConfig[]
props?: Dictionary<boolean | Object | RoutePropsFunction>
}

export type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews

export interface RouteRecord {
path: string
regex: RegExp
Expand Down
3 changes: 3 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Vue.use(VueRouter)
const Home = { template: '<div>home</div>' }
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Abc = { template: '<div>abc</div>' }
const Async = () => Promise.resolve({ template: '<div>async</div>' })

const Hook: ComponentOptions<Vue> = {
Expand Down Expand Up @@ -76,6 +77,7 @@ const router = new VueRouter({
components: {
default: Foo,
bar: Bar,
abc: Abc,
asyncComponent: Async
},
meta: { auth: true },
Expand All @@ -88,6 +90,7 @@ const router = new VueRouter({
props: {
default: true,
bar: { id: 123 },
abc: route => route.params,
asyncComponent: (route: Route) => route.params
}
},
Expand Down