@@ -123,6 +123,83 @@ describe('react-router-component (on server)', function() {
123123
124124 } ) ;
125125
126+
127+ describe ( 'nested contextual routers' , function ( ) {
128+
129+ var Level2 = React . createClass ( {
130+
131+ render : function ( ) {
132+ return Router . Locations ( { className : 'L2' , contextual : true } ,
133+ Router . Location ( {
134+ path : '/' ,
135+ handler : function ( props ) {
136+ return Router . Link ( { href : '/hello' } ) ;
137+ }
138+ } ) ,
139+ Router . Location ( {
140+ path : '/:slug' ,
141+ handler : function ( props ) {
142+ return Router . Link ( { global : true , href : '/hi' } ) ;
143+ }
144+ } )
145+ )
146+ }
147+ } ) ;
148+
149+ var Level1 = React . createClass ( {
150+
151+ render : function ( ) {
152+ return Router . Locations ( { className : 'L1' , contextual : true } ,
153+ Router . Location ( {
154+ path : '/' ,
155+ handler : function ( props ) {
156+ return Router . Link ( { href : '/l2' } ) ;
157+ }
158+ } ) ,
159+ Router . Location ( {
160+ path : '/:slug(/*)' ,
161+ handler : Level2
162+ } )
163+ )
164+ }
165+ } ) ;
166+
167+ var App = React . createClass ( {
168+
169+ render : function ( ) {
170+ return Router . Locations ( { className : 'App' , path : this . props . path } ,
171+ Router . Location ( {
172+ path : '/l1/:slug(/*)' ,
173+ handler : Level1
174+ } )
175+ ) ;
176+ }
177+ } ) ;
178+
179+ it ( 'renders Link component with href scoped to its prefix' , function ( ) {
180+ var markup = React . renderComponentToString ( App ( { path : '/l1/nice' } ) ) ;
181+ assert ( markup . match ( / c l a s s = " A p p " / ) ) ;
182+ assert ( markup . match ( / c l a s s = " L 1 " / ) ) ;
183+ assert ( markup . match ( / h r e f = " & # x 2 f ; l 1 & # x 2 f ; n i c e & # x 2 f ; l 2 " / ) ) ;
184+ } ) ;
185+
186+ it ( 'renders nested Link component with href scoped to its prefix' , function ( ) {
187+ var markup = React . renderComponentToString ( App ( { path : '/l1/nice/l2' } ) ) ;
188+ assert ( markup . match ( / c l a s s = " A p p " / ) ) ;
189+ assert ( markup . match ( / c l a s s = " L 1 " / ) ) ;
190+ assert ( markup . match ( / c l a s s = " L 2 " / ) ) ;
191+ assert ( markup . match ( / h r e f = " & # x 2 f ; l 1 & # x 2 f ; n i c e & # x 2 f ; l 2 & # x 2 f ; h e l l o " / ) ) ;
192+ } ) ;
193+
194+ it ( 'renders global Link component with correct href (not scoped to a router)' , function ( ) {
195+ var markup = React . renderComponentToString ( App ( { path : '/l1/nice/l2/foo' } ) ) ;
196+ assert ( markup . match ( / c l a s s = " A p p " / ) ) ;
197+ assert ( markup . match ( / c l a s s = " L 2 " / ) ) ;
198+ assert ( markup . match ( / h r e f = " & # x 2 f ; h i " / ) ) ;
199+ } ) ;
200+
201+ } ) ;
202+
126203 describe ( 'async router' , function ( ) {
127204 var App = React . createClass ( {
128205
0 commit comments