I have this exact stack - you don't need to worry about handling each 
specific possible route on the express side.  Just put the entire app in a 
statically served directory on your node server, and set up a single route 
to that at the root context.

app.use(_express.static("app"));

My "app" directory looks like this:

index.html
[js]
[css]
[partials]
[etc]

On Sunday, November 4, 2012 5:16:36 PM UTC-8, Matt Reyer wrote:
>
> I'm using Express, which loads AngularJS from a static directory. 
> Normally, I will request http://localhost/, in which Express serves me my 
> index.html and all of the correct Angular files, etc. In my Angular app, 
> I have these routes setup, which replace the content in an ng-view:
>
> $routeProvider.when('/', {
>     templateUrl: '/partials/main.html',
>     controller: MainCtrl,});
>
> $routeProvider.when('/project/:projectId', {
>     templateUrl: '/partials/project.html',
>     controller: ProjectCtrl,});
>
> $locationProvider.html5Mode(true);
>
> On my main page, I have a link to <a href="/project/{{project.id}}">, 
> which will successfully load the template and direct me to 
> http://localhost/project/3 or whatever ID I have specified. The problem 
> is when I try to direct my browser to http://localhost/project/3 or 
> refresh the page, the request is going to the Express/Node server, which 
> returns Cannot GET /project/3. 
>
> How do I setup my Express routes to accommodate for this? I'm guessing it 
> will require the use of 
> $location<http://docs.angularjs.org/guide/dev_guide.services.%24location>in 
> Angular (although I'd prefer to avoid the ugly ?searches and #hashes 
> they use), but I'm clueless about how to go about setting up the Express 
> routes to handle this.
>
>
> StackOverflow:  
> http://stackoverflow.com/questions/13222252/how-to-use-angularjs-routes-with-express-node-js-when-a-new-page-is-requested
>  

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to