我創建路由五月網頁這樣無法加載刷新路線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)
那麼,什麼是錯誤? – digit
您不必爲每條路徑設置新路線。只留下一個,並將其設置爲'*'(快速) –
@Patryk我已經嘗試將'/ *'更改爲'*',但仍然不起作用 –