nuxt-typed-router
Advanced tools
Comparing version
@@ -7,3 +7,3 @@ import fs from 'fs'; | ||
export default function routeModules(moduleOptions) { | ||
export default moduleOptions => { | ||
const options = Object.assign({}, this.options.axios, moduleOptions); | ||
@@ -34,6 +34,4 @@ | ||
const template = ` | ||
export const routerPagesNames = ${routesInterfaces}; | ||
`; | ||
const routesEnumsTemplate = `export type RouteNames = ${routesEnum.join('|')}; | ||
`; | ||
export const routerPagesNames = ${routesInterfaces};`; | ||
const routesEnumsTemplate = `export type RouteNames = ${routesEnum.join('|')};`; | ||
@@ -64,2 +62,4 @@ try { | ||
}); | ||
} | ||
}; | ||
module.exports.meta = require('../package.json'); |
import Vue from 'vue'; | ||
export default (ctx, inject) => { | ||
inject('safeRouter', ctx.app.router); | ||
inject('safeRoute', ctx.route); | ||
inject('typedRouter', ctx.app.router); | ||
inject('typedRoute', ctx.route); | ||
}; |
{ | ||
"name": "nuxt-typed-router", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Provide autocompletion for pages route names generated by Nuxt router", | ||
@@ -30,3 +30,4 @@ "main": "lib/module.js", | ||
"vue-router": "^3.1.3" | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
import Vue from 'vue'; | ||
import { SafeVueRouter, SafeRoute } from './vue'; | ||
import { TypedVueRouter, TypedRoute } from './vue'; | ||
import './vue'; | ||
@@ -11,6 +11,6 @@ | ||
interface Context { | ||
$safeRouter: SafeVueRouter; | ||
$typedRouter: TypedVueRouter; | ||
} | ||
interface NuxtAppOptions { | ||
$safeRouter: SafeVueRouter; | ||
$typedRouter: TypedVueRouter; | ||
} | ||
@@ -27,6 +27,6 @@ interface Configuration { | ||
interface Context { | ||
$safeRouter: SafeVueRouter; | ||
$typedRouter: TypedVueRouter; | ||
} | ||
interface NuxtAppOptions { | ||
$safeRouter: SafeVueRouter; | ||
$typedRouter: TypedVueRouter; | ||
} | ||
@@ -37,4 +37,4 @@ } | ||
interface Vue { | ||
$safeRouter: SafeVueRouter; | ||
$safeRoute: SafeRoute; | ||
$typedRouter: TypedVueRouter; | ||
$typedRoute: TypedRoute; | ||
} | ||
@@ -45,4 +45,4 @@ } | ||
interface Store<S> { | ||
$safeRouter: SafeVueRouter; | ||
$typedRouter: TypedVueRouter; | ||
} | ||
} |
import VueRouter, { Location, Route, RouteRecord } from 'vue-router'; | ||
import { RouteNames } from './__generated'; | ||
import { RouteNames } from 'nuxt-typed-router/__generated'; | ||
import { ErrorHandler } from 'vue-router/types/router'; | ||
import { ComponentOptions } from 'vue/types/umd'; | ||
import Vue, { AsyncComponent } from 'vue'; | ||
import Vue, { AsyncComponent, ComponentOptions } from 'vue'; | ||
type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent; | ||
export interface NuxtTypedRouterOptions { | ||
filePath?: string; | ||
} | ||
export type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent; | ||
export interface SafeVueRouter extends VueRouter { | ||
push(location: SafeRawLocation): Promise<SafeRoute>; | ||
replace(location: SafeRawLocation): Promise<SafeRoute>; | ||
push(location: SafeRawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; | ||
replace(location: SafeRawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; | ||
getMatchedComponents(to?: SafeRawLocation | SafeRoute): Component[]; | ||
export interface TypedVueRouter extends VueRouter { | ||
push(location: TypedRawLocation): Promise<TypedRoute>; | ||
replace(location: TypedRawLocation): Promise<TypedRoute>; | ||
push(location: TypedRawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; | ||
replace(location: TypedRawLocation, onComplete?: Function, onAbort?: ErrorHandler): void; | ||
getMatchedComponents(to?: TypedRawLocation | TypedRoute): Component[]; | ||
resolve( | ||
to: SafeRawLocation, | ||
current?: SafeRoute, | ||
to: TypedRawLocation, | ||
current?: TypedRoute, | ||
append?: boolean | ||
): { | ||
location: SafeLocation; | ||
route: SafeRoute; | ||
location: TypedLocation; | ||
route: TypedRoute; | ||
href: string; | ||
normalizedTo: SafeLocation; | ||
resolved: SafeRoute; | ||
normalizedTo: TypedLocation; | ||
resolved: TypedRoute; | ||
}; | ||
} | ||
type SafeRawLocation = string | SafeLocation; | ||
export type TypedRawLocation = string | TypedLocation; | ||
export interface SafeLocation extends Location { | ||
export interface TypedLocation extends Location { | ||
name?: RouteNames; | ||
} | ||
export interface SafeRoute extends Route { | ||
export interface TypedRoute extends Route { | ||
name?: RouteNames; | ||
} | ||
export interface SafeRouteRecord extends RouteRecord { | ||
export interface TypedRouteRecord extends RouteRecord { | ||
name?: RouteNames; | ||
} |
6153
2.41%136
0.74%