File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
packages/router/src/volar/entries Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,20 @@ import type ts from 'typescript'
1717const plugin : VueLanguagePlugin = ( {
1818 compilerOptions,
1919 modules : { typescript : ts } ,
20+ ...options
2021} ) => {
22+ // rootDir comes from plugin options (vuejs/language-tools#5678)
23+ const optionsRootDir = ( options as { rootDir ?: string } ) . rootDir
24+ // Prioritize plugin options over tsconfig
25+ const rootDir = optionsRootDir ?? compilerOptions . rootDir
26+
27+ // Warn if no rootDir specified
28+ if ( ! rootDir ) {
29+ console . warn (
30+ '[vue-router] No rootDir specified. Set it in the Volar plugin options or tsconfig compilerOptions.rootDir for proper typed routes.'
31+ )
32+ }
33+
2134 const RE = {
2235 DOLLAR_ROUTE : {
2336 /**
@@ -38,9 +51,7 @@ const plugin: VueLanguagePlugin = ({
3851 // TODO: Do we want to apply this to EVERY .vue file or only to components that the user wrote themselves?
3952
4053 // NOTE: this might not work if different from the root passed to VueRouter unplugin
41- const relativeFilePath = compilerOptions . rootDir
42- ? relative ( compilerOptions . rootDir , fileName )
43- : fileName
54+ const relativeFilePath = rootDir ? relative ( rootDir , fileName ) : fileName
4455
4556 const useRouteNameType = `import('vue-router/auto-routes')._RouteNamesForFilePath<'${ relativeFilePath } '>`
4657 const useRouteNameTypeParam = `<${ useRouteNameType } >`
You can’t perform that action at this time.
0 commit comments