2017-02-07 11 views
8

जोड़ रहा है, मैं रूटिंग के माध्यम से अपने ऐप में एक मोडल लॉन्च करने का प्रयास कर रहा हूं। सब कुछ काम करने लगता है सिवाय इसके कि यूआरएल में एक अतिरिक्त स्लैश जोड़ा जाता है जो इसे हल करने से रोकता है। यूआरएल इस तरह दिखना चाहिए (और यह काम करता है, तो मैं इसे मैन्युअल रूप से दर्ज) ...राउटरलिंक के माध्यम से नामित आउटलेट को लक्षित करना अतिरिक्त "/"

/accounts(modal:accounts/1/edit) 

लेकिन मैं इस (आधार यूआरएल और आउटलेट लक्ष्य के बीच स्लेश नोटिस) के बजाय हो रही है ...

/accounts/(modal:accounts/1/edit) 

आधार टैग सेट कर दिया जाता ...

<head> 
    <meta charset="utf-8"> 
    <title>myApp</title> 
    <base href="/"> 
    ... 
</head> 

यहाँ मेरी मार्ग config है (खातों-routing.module.ts)

const ACCOUNT_ROUTES: Routes = [ 
    { 
    path: 'accounts', 
    component: AccountsIndexComponent 
    },{ 
    path: 'accounts/new', 
    component: AccountsNewComponent 
    },{ 
    path: 'accounts/:id', 
    component: AccountsShowComponent 
    },{ 
    path: 'accounts/:id/edit', 
    component: AccountsEditComponent, 
    outlet: 'modal' 
    } 
]; 

और आउटलेट (app.component.html)

<router-outlet></router-outlet> 
<router-outlet name="modal"></router-outlet> 

और लिंक ...

<a [routerLink]="[{ outlets: { modal: ['accounts', account.id, 'edit'] } }]">Edit</a> 

मैं क्या याद आ रही है? परियोजना [email protected] और [email protected] और [email protected] का उपयोग कर बनाई गई थी।

Fwiw, यहां लॉग के एक स्क्रीनशॉट है ...

failed routing attempt

+0

क्या आपने 'index href = "/"> '' index.html'-file में जोड़ा है? – unitario

+0

yup, '' -tag के पहले बच्चे के रूप में ' 'टैग – Brian

+0

है? मुझे लगता है कि आपकी समस्या यह हो सकती है कि पथ कैसे हल किए जाते हैं। – unitario

उत्तर

17

ठीक लिंक पर एक खाली रिश्तेदार पथ को परिभाषित किया गया था। सही दिशा में मुझे इंगित करने के लिए @unitario के लिए धन्यवाद!

<a [routerLink]="['', { outlets: { modal: ['accounts', account.id, 'edit'] } }]">Edit</a> 
+0

In our application we have an authentication modal that can open over any view so any initial path caused issues, either by loosing the current route or by adding extra slash. This solved the issue, Thank you! the only thing added is queryParamsHandling="merge" to facilitate passing parameters to the modal and the underlying view '' – Greg

संबंधित मुद्दे