2014-12-03 2 views
1

내 app.js에 html5mode (true)를 설정했습니다.AngularJS가있는 loopbackJS의 이상한 동작

$routeProvider.when('/hello/there', { 
templateUrl: 'partials/hello.html', 
controller : 'HelloCtrl' 
}); 


// if none of the above routes are met, use this fallback 
// which executes the 'AppCtrl' controller (controllers.js) 
$routeProvider.otherwise({ 
redirectTo: '/' 
}); 
$locationProvider.html5Mode(true); 

을 다음하지만 http://localhost:3000/hello/there

를 탐색 할 때 그것은 루프백 raiseUrlNotFoundError으로 404 오류를 thowing대로 내 코드입니다. html5Mode (false)를 설정하면 모두 정상적으로 작동합니다.

html5Mode를 true로 만드는 방법은 무엇입니까? 사전에

덕분에 당신은 서버 측에서 모든 경로를 리디렉션 할 필요가

+0

같은 정적 파일 후이 middlware가, 곧 다시 얻을 것이다 middlware.json 통화에서

module.exports = serveindex; function serveindex(){ return function(req, res){ res.sendFile("index.html", {root: __dirname+"/../../client"}) } } 

그런 다음 서버/middlware/serveindex.js의 기능입니다. – superkhau

답변

2

:

... 
// -- Mount static files here-- 
// All static middleware should be registered at the end, as all requests 
// passing the static middleware are hitting the file system 
// Example: 
app.use(loopback.static(path.resolve(__dirname, '../client'))); //mount static files first 
... 
app.all("/*", ...) //then redirect all routes 
... 
3

당신이 server.js 또는 서버에 있음을했다면 /를 부팅 :

server.js에서 이 정적 middlware 전에 제공 될 것이기 때문에 모든 정적 파일 (js, css, imgs)이 먼저이 middlware를 통해 오류을 많이 포착하면 해결 될 것입니다. 새로운 middlw를 추가하는 것입니다. 이것으로 보면이

"files": { 
"loopback#static": { 
    "params": "$!../client" 
    } 
}, 
"files:after": { 
"./middleware/serveindex":{ 
    "enabled": true 
    } 
},