2017-02-25 19 views
2

我創建路由五月網頁這樣無法加載刷新路線PARAMS後指數

angular.module("ui",[]).config(function($routeProvider,$locationProvider,$httpProvider) 
{ 
    $routeProvider.when('/home', 
    { 
    templateUrl: 'home.html' 

    }) 
    .when('/login', 
    { 
    templateUrl: 'login.html' 

    }) 
    .when('/sign_in', 
    { 
    templateUrl: 'create_account.html' 

    }) 
    .when('/profil', 
    { 
    templateUrl: 'profil.html' 

    }) 
    .when('/note/:id', 
    { 
    templateUrl: 'view_note.html' 

    }) 
    .when('/editNote/:id', 
    { 
    templateUrl: 'edit_note.html' 

    }) 
    .otherwise({ 
    redirectTo: '/home' 
    }); 
    $locationProvider.html5Mode(true); 
}); 

和服務器端代碼(expressjs)

app.get('/*', function(req, res) { 
    res.sendFile(__dirname + '/views/index.html') 
}); 
app.get('/note/:id', function(req, res) { 
    res.sendFile(__dirname + '/views/index.html') 
}); 
app.get('/note/*', function(req, res) { 
    res.sendFile(__dirname + '/views/index.html') 
}); 
app.get('/:id', function(req, res) { 
    res.sendFile(__dirname + '/views/index.html') 
}); 

所以我所有的路由配置運行完美但是當我嘗試刷新我的頁面時,幾乎所有的頁面都運行正常,除了帶有/editNote/:id路由配置的頁面。那麼如何解決這個服務器端的路由問題(expressjs)

enter image description here

+0

那麼,什麼是錯誤? – digit

+0

您不必爲每條路徑設置新路線。只留下一個,並將其設置爲'*'(快速) –

+0

@Patryk我已經嘗試將'/ *'更改爲'*',但仍然不起作用 –

回答

0

終於可以找出真正的問題,它之間的路由同名的原因貓鼬路線和express/angularjs路線。所以我改變了angularjs的路由名稱

0

在服務器上添加文件:

app.use('/*', function (req, res) { res.sendFile(__dirname + '/views/index.html'); });

刪除

app.get('/note/*', function(req, res) { 
    res.sendFile(__dirname + '/views/index.html') 
}); 
+0

仍然一樣,即使我將'/ *'更改爲'* ' –

+0

即使您刪除了所有'/ *',?發生我從來沒有像這樣的網址。 –

+0

是的,它仍然是相同的 –