44goog . module ( 'stack.ui.Select' ) ;
55
66const TabEvent = goog . require ( 'stack.ui.TabEvent' ) ;
7+ const Template = goog . require ( 'stack.ui.Template' ) ;
78const asserts = goog . require ( 'goog.asserts' ) ;
89const dom = goog . require ( 'goog.dom' ) ;
910const { Component, Route } = goog . require ( 'stack.ui' ) ;
@@ -38,7 +39,6 @@ class Select extends Component {
3839 * @private @type {?string }
3940 */
4041 this . prev_ = null ;
41-
4242 }
4343
4444 /**
@@ -169,7 +169,6 @@ class Select extends Component {
169169 }
170170 }
171171
172-
173172 /**
174173 * @param {string } name
175174 * @param {!Route } route
@@ -184,14 +183,33 @@ class Select extends Component {
184183 }
185184 }
186185
187-
188186 /**
189187 * @param {string } name
190188 * @param {!Route } route
191189 */
192190 selectFail ( name , route ) {
193- route . fail ( this , 'No tab for ' + name + ' in ' + JSON . stringify ( this . name2id_ ) ) ;
194- // this.getApp().handle404(route);
191+ const notFound = this . getNotFoundTemplate ( ) ;
192+ if ( notFound ) {
193+ this . selectNotFound ( name , route , notFound ) ;
194+ } else {
195+ route . fail ( this , `No tab for ${ name } in ${ JSON . stringify ( this . name2id_ ) } ` ) ;
196+ }
197+ }
198+
199+ /**
200+ * The base case when the tab is not found.
201+ * @param {string } name
202+ * @param {!Route } route
203+ * @param {!Function } template
204+ */
205+ selectNotFound ( name , route , template ) {
206+ this . addTab ( name , new Template ( template , {
207+ name : name ,
208+ route : route ,
209+ } , {
210+ pathURL : this . getPathUrl ( ) ,
211+ } ) ) ;
212+ this . select ( name , route ) ;
195213 }
196214
197215 /**
@@ -206,7 +224,6 @@ class Select extends Component {
206224 return null ;
207225 }
208226
209-
210227 /**
211228 * Hide the current tab and make it the previous.
212229 * @return {?Component }
@@ -224,6 +241,14 @@ class Select extends Component {
224241 return prev ;
225242 }
226243
244+ /**
245+ * A function to be overridden by subclasses to opt-in
246+ * to the not-found template.
247+ * @returns {?Function } template
248+ */
249+ getNotFoundTemplate ( ) {
250+ return null ;
251+ }
227252}
228253
229254exports = Select ;
0 commit comments