@@ -100,8 +100,11 @@ export class BaseFileSystemRouter extends EventTarget {
100100 update = undefined ;
101101
102102 _addRoute ( route : Route ) {
103- this . routes = this . routes . filter ( r => r . path !== route . path ) ;
103+ const idx = this . routes . findIndex ( r => r . path === route . path ) ;
104+ if ( idx >= 0 ) this . routes . splice ( idx , 1 ) ;
104105 this . routes . push ( route ) ;
106+
107+ return idx >= 0 ;
105108 }
106109
107110 async addRoute ( src : string ) {
@@ -130,14 +133,16 @@ export class BaseFileSystemRouter extends EventTarget {
130133 ) ;
131134 }
132135
133- async updateRoute ( src : string ) {
134- src = normalizePath ( src ) ;
136+ async updateRoute ( src_ : string ) {
137+ const src = normalizePath ( src_ ) ;
135138 if ( this . isRoute ( src ) ) {
136139 try {
137140 const route = this . toRoute ( src ) ;
138141 if ( route ) {
139- this . _addRoute ( route ) ;
140- this . reload ( route . path , "update" ) ;
142+ const updated = this . _addRoute ( route ) ;
143+ this . reload ( route . path , updated ? "update" : "add" ) ;
144+ } else {
145+ this . removeRoute ( src_ ) ;
141146 }
142147 } catch ( e ) {
143148 console . error ( e ) ;
@@ -153,7 +158,11 @@ export class BaseFileSystemRouter extends EventTarget {
153158 if ( path === undefined ) {
154159 return ;
155160 }
156- this . routes = this . routes . filter ( r => r . path !== path ) ;
161+
162+ const idx = this . routes . findIndex ( r => r . path === path ) ;
163+ if ( idx === - 1 ) return ;
164+
165+ this . routes . splice ( idx , 1 ) ;
157166 this . reload ( path , "remove" ) ;
158167 }
159168 }
0 commit comments