2017-01-02 47 views
0

我在做一個使用OAuth的應用程序,所以首先加載一個php頁面以使用OAuth進行身份驗證。當完成回調php腳本重定向到我的角度應用程序的開始頁面。在URL中獲取「#!/(state)」AngularJS狀態

// Redirect user to the startpage of the application 
header("location: http://localhost/app/start.html"); 

在這裏,Angular被實例​​化,所有的腳本都被加載,並且stateprovider應該在這裏重定向到.otherwise狀態。

app 
.config(function($stateProvider, $urlRouterProvider){ 

$urlRouterProvider.otherwise('main/front'); 

$stateProvider 
.state('main',{ 
    url: '/main', 
    abstract: true, 
    templateUrl:'templates/menu.html' 
}) 

    .state('main.frontpage',{ 
     url: '/front', 
     templateUrl:'templates/frontPage.html' 
    }) 
}); 

重定向工作正常,我得到正確的網頁主/前雖然我得到一個奇怪的URL,它的JQuery保持驚人的。

http://localhost/app/start.html#!/main/front

JQuery的錯誤:

Uncaught Error: Syntax error, unrecognized expression: #!/main/front

爲什麼網址獲得#!在那裏登錄?

編輯:JQuery錯誤似乎被拋出其他地方。與這個問題無關。

回答

1

我用下面的代碼解決了。

$locationProvider.hashPrefix(''); 

要不然去 Routing issue with AngularJS project using yeoman setup

+0

我通過兔子洞去,並得到了他們推薦降級到1.5角的頁面https://github.com/yeoman/generator-angular/issues/1380 0.8。 這似乎刪除了「!」,仍然留下「#」。 JQuery仍然在此錯誤 >「未捕獲的錯誤:語法錯誤,無法識別的表達式:#/前」 –

+0

沒有必要降級@TimothyKarvonen,你可以檢查後,我的版本沒有改變後加入 – Shiva

+0

正確,與您的解決方案@Shiva它刪除了「!」在角度1.6.0。那麼爲什麼JQuery抱怨網址? –