@@ -17,7 +17,7 @@ import type {
1717
1818import { warn } from '../warning'
1919import { assign , noop } from '../utils'
20- import type { RouteRecordName , RouteRecordNameGeneric , _RouteRecordProps } from '../typed-routes'
20+ import type { RouteRecordName , _RouteRecordProps } from '../typed-routes'
2121
2222/**
2323 * Internal RouterMatcher
@@ -26,13 +26,13 @@ import type { RouteRecordName, RouteRecordNameGeneric, _RouteRecordProps } from
2626 */
2727export interface RouterMatcher {
2828 addRoute : ( record : RouteRecordRaw , parent ?: RouteRecordMatcher ) => ( ) => void
29- removeRoute ( matcher : RouteRecordMatcher ) : void
30- removeRoute ( name : NonNullable < RouteRecordNameGeneric > ) : void
29+ removeRoute : {
30+ ( matcher : RouteRecordMatcher ) : void
31+ ( name : RouteRecordName ) : void
32+ }
3133 clearRoutes : ( ) => void
3234 getRoutes : ( ) => RouteRecordMatcher [ ]
33- getRecordMatcher : (
34- name : NonNullable < RouteRecordNameGeneric >
35- ) => RouteRecordMatcher | undefined
35+ getRecordMatcher : ( name : RouteRecordName ) => RouteRecordMatcher | undefined
3636
3737 /**
3838 * Resolves a location. Gives access to the route record that corresponds to the actual path as well as filling the corresponding params objects
@@ -65,7 +65,7 @@ export function createRouterMatcher(
6565 globalOptions
6666 )
6767
68- function getRecordMatcher ( name : NonNullable < RouteRecordNameGeneric > ) {
68+ function getRecordMatcher ( name : RouteRecordName ) {
6969 return matcherMap . get ( name )
7070 }
7171
@@ -157,12 +157,6 @@ export function createRouterMatcher(
157157 removeRoute ( record . name )
158158 }
159159
160- // Avoid adding a record that doesn't display anything. This allows passing through records without a component to
161- // not be reached and pass through the catch all route
162- if ( isMatchable ( matcher ) ) {
163- insertMatcher ( matcher )
164- }
165-
166160 if ( mainNormalizedRecord . children ) {
167161 const children = mainNormalizedRecord . children
168162 for ( let i = 0 ; i < children . length ; i ++ ) {
@@ -182,6 +176,17 @@ export function createRouterMatcher(
182176 // if (parent && isAliasRecord(originalRecord)) {
183177 // parent.children.push(originalRecord)
184178 // }
179+
180+ // Avoid adding a record that doesn't display anything. This allows passing through records without a component to
181+ // not be reached and pass through the catch all route
182+ if (
183+ ( matcher . record . components &&
184+ Object . keys ( matcher . record . components ) . length ) ||
185+ matcher . record . name ||
186+ matcher . record . redirect
187+ ) {
188+ insertMatcher ( matcher )
189+ }
185190 }
186191
187192 return originalMatcher
@@ -192,9 +197,7 @@ export function createRouterMatcher(
192197 : noop
193198 }
194199
195- function removeRoute (
196- matcherRef : NonNullable < RouteRecordNameGeneric > | RouteRecordMatcher
197- ) {
200+ function removeRoute ( matcherRef : RouteRecordName | RouteRecordMatcher ) {
198201 if ( isRouteName ( matcherRef ) ) {
199202 const matcher = matcherMap . get ( matcherRef )
200203 if ( matcher ) {
@@ -337,7 +340,6 @@ export function createRouterMatcher(
337340 routes . forEach ( route => addRoute ( route ) )
338341
339342 function clearRoutes ( ) {
340- matchers . length = 0
341343 matcherMap . clear ( )
342344 }
343345
0 commit comments