File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,6 +198,26 @@ class Config {
198198 return this . routesDef ;
199199 }
200200
201+ /**
202+ * Returns the primary route.
203+ *
204+ * The primary route is the one marked primary in `routes.yaml`, or else
205+ * the first non-redirect route in that file if none are marked.
206+ *
207+ * @return {object }
208+ * The route definition. The generated URL of the route is added as a "url" key.
209+ */
210+ getPrimaryRoute ( ) {
211+ // eslint-disable-next-line no-unused-vars
212+ for ( const [ url , route ] of Object . entries ( this . routes ( ) ) ) {
213+ if ( route . primary === true ) {
214+ return route ;
215+ }
216+ }
217+
218+ throw new Error ( `No primary route found. This isn't supposed to happen.` ) ;
219+ }
220+
201221 /**
202222 * Returns a single route definition.
203223 *
Original file line number Diff line number Diff line change @@ -166,6 +166,14 @@ describe("Config tests", () => {
166166 } ) ;
167167 } ) ;
168168
169+ it ( 'gets the primary route' , ( ) => {
170+ let c = new psh . Config ( mockEnvironmentRuntime ) ;
171+
172+ let route = c . getPrimaryRoute ( ) ;
173+
174+ assert . equal ( route [ 'original_url' ] , 'https://www.{default}/' ) ;
175+ } ) ;
176+
169177 it ( 'gets a route by id' , ( ) => {
170178 let c = new psh . Config ( mockEnvironmentRuntime ) ;
171179
You can’t perform that action at this time.
0 commit comments