@@ -117,6 +117,8 @@ class MipShell extends CustomElement {
117117 window . MIP_SHELL_ROUTES_AUTO_GENERATED = true
118118 }
119119
120+ this . mergeCambrianData ( tmpShellConfig )
121+
120122 if ( page . isRootPage ) {
121123 tmpShellConfig . routes . forEach ( route => {
122124 ! this . ignoreWarning && checkRouteConfig ( route )
@@ -208,6 +210,61 @@ class MipShell extends CustomElement {
208210 }
209211 }
210212
213+ mergeCambrianData ( tmpShellConfig ) {
214+ let cambrianObj ;
215+ let hashObj = { }
216+ if ( location . hash ) {
217+ let tmpHashArr = location . hash . replace ( '#' , '' ) . split ( '&' )
218+ tmpHashArr . forEach ( hashStr => {
219+ let hashSplitArr = hashStr . split ( '=' )
220+ hashObj [ hashSplitArr [ 0 ] ] = hashSplitArr [ 1 ] || ''
221+ } )
222+ }
223+
224+ // hash 传入的 logo 和 title 的优先级比直接配置在当前的 path 上的低,要比 * 的优先级高
225+ if ( hashObj . cambrian ) {
226+ try {
227+ cambrianObj = JSON . parse ( decodeURIComponent ( hashObj . cambrian ) )
228+ // 如果传入的参数出错或者解析不成功,就忽略这个 hash 参数
229+ } catch ( e ) { }
230+ }
231+
232+ if ( cambrianObj && cambrianObj . title ) {
233+ let cambrianRoute = {
234+ pattern : location . pathname ,
235+ meta : {
236+ header : {
237+ show : true ,
238+ title : cambrianObj . title || '' ,
239+ logo : cambrianObj . logo || ''
240+ } ,
241+ view : {
242+ isIndex : true
243+ }
244+ }
245+ }
246+
247+ if ( tmpShellConfig . routes && tmpShellConfig . routes . length ) {
248+ let injectFlag = true
249+
250+ for ( let i = 0 ; i < tmpShellConfig . routes . length ; i ++ ) {
251+ let route = tmpShellConfig . routes [ i ]
252+ let re = convertPatternToRegexp ( route . pattern )
253+ if ( route . pattern !== '*' && re . test ( page . pageId ) ) {
254+ tmpShellConfig . routes [ i ] = fn . extend ( true , { } , cambrianRoute , route )
255+ injectFlag = false
256+ break
257+ }
258+ }
259+ injectFlag && tmpShellConfig . routes . unshift ( cambrianRoute )
260+ } else {
261+ tmpShellConfig . routes = cambrianRoute
262+ }
263+ }
264+
265+ console . log ( tmpShellConfig , page )
266+ }
267+
211268 prerenderAllowed ( ) {
212269 return true
213270 }
0 commit comments