Skip to content

Commit f5b98bf

Browse files
committed
fix: add null check for plugin install method
Add early validation for app parameter to prevent TypeError when accessing properties of null/undefined values and ensure consistent error messages.
1 parent d59dfef commit f5b98bf

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

packages/router-vue/src/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ describe('index.ts - Package Entry Point', () => {
2525
expect(RouterVueModule.useLink).toBeDefined();
2626
expect(typeof RouterVueModule.useLink).toBe('function');
2727
});
28+
29+
it('should export useRouterViewDepth function', () => {
30+
expect(RouterVueModule.useRouterViewDepth).toBeDefined();
31+
expect(typeof RouterVueModule.useRouterViewDepth).toBe('function');
32+
});
33+
34+
it('should export getRouterViewDepth function', () => {
35+
expect(RouterVueModule.getRouterViewDepth).toBeDefined();
36+
expect(typeof RouterVueModule.getRouterViewDepth).toBe('function');
37+
});
2838
});
2939

3040
describe('Options API Exports', () => {
@@ -74,6 +84,7 @@ describe('index.ts - Package Entry Point', () => {
7484
'useProvideRouter',
7585
'useLink',
7686
'useRouterViewDepth',
87+
'getRouterViewDepth',
7788
// Options API
7889
'getRouter',
7990
'getRoute',
@@ -100,6 +111,7 @@ describe('index.ts - Package Entry Point', () => {
100111
'useProvideRouter',
101112
'useLink',
102113
'useRouterViewDepth',
114+
'getRouterViewDepth',
103115
'getRouter',
104116
'getRoute',
105117
'RouterLink',
@@ -217,6 +229,8 @@ describe('index.ts - Package Entry Point', () => {
217229
'useRoute',
218230
'useProvideRouter',
219231
'useLink',
232+
'useRouterViewDepth',
233+
'getRouterViewDepth',
220234
'getRouter',
221235
'getRoute'
222236
];

packages/router-vue/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
useProvideRouter,
88
useLink,
99
useRouterViewDepth,
10+
getRouterViewDepth,
1011
getRoute,
1112
getRouter
1213
} from './use';

packages/router-vue/src/plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export const RouterPlugin = {
7171
* @param app Vue application instance (Vue 3) or Vue constructor (Vue 2)
7272
*/
7373
install(app: unknown): void {
74+
if (!app) {
75+
throw new Error('[@esmx/router-vue] Invalid Vue app instance');
76+
}
77+
7478
const vueApp = app as VueApp;
7579
const target = vueApp.config?.globalProperties || vueApp.prototype;
7680

0 commit comments

Comments
 (0)