2017-07-18 107 views
0

重定向到外部URL的纖維環在我的菜單definiton我有類似的東西:如何從進入菜單

... 
function routeConf($stateProvider) { 
    $stateProvider.state({ 
     name: 'application.users', 
     url: '/users' // in this place I would like to replace with http://google.com 
    }) 
} 

    .. 

我想達到這個點擊此按鈕將其重定向到外部URL,如效果。 http://google.com。我不知道Angular。你可以幫我嗎?
當我點擊一個按鈕時,它將移動到/home/users。 當我replcaee url : /dogs它移動到/home/dogs。正如你所看到的,它附加後綴。

如何強制未追加(爲了使人們有可能轉會到google

回答

1

在您看來,綁定click事件到組件方法:

<button (click)="openUrl('www.google.com')">button</button> 

而且在使用的組件,window.location.href使重定向:

openUrl(siteWeb: string) { 

    let link = siteWeb; 

    let httpPrefix = "http://"; 
    if (!siteWeb.startsWith(httpPrefix)) { 
     link = httpPrefix + siteWeb 
    } 

    window.location.href = link; 
    } 

注意:您的聯繫必須以http://作爲前綴以進行外部導航。

+0

我想使用我目前的應用 - 這意味着按鈕連接到模塊,模塊定義狀態。 –

+0

你是什麼意思按鈕連接到模塊?你叫什麼模塊? –

+0

我編輯並澄清了我將要做的事情。 –