Home:ALL Converter>Angular routing is not working with express

Angular routing is not working with express

Ask Time:2016-01-17T13:39:36         Author:Nitya

Json Formatter

I am doing a sample MEAN application.I have my angular routing but when I am making any request it is directly hitting the server and giving me a Cannot GET /movies.

Here below is my server side code for serving static files.

 //Serve html files
app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

//Register all the client folder
var client = __dirname + '/modules';
fs.readdir(client, function(err,files) {
    files.map(function(file){
        app.use(express.static(path.join(__dirname, '/modules'+'/'+file+'/client')));
    })
});

//Serve js files
app.use(express.static(path.join(__dirname, '/public')));

//Load the models
app.models = require('./index');

//Load the routes
var routes = require('./routes');
_.each(routes,function(controller,route){
    app.use(route,controller(app,route));
});

Inside my client folder another folder called 'view' is there where all my templates are there.

Below is my routing for /movie URL

angular.module('movies').config(['$stateProvider',
  function ($stateProvider) {
    // Movies state routing
    $stateProvider
      .state('movies.list', {
        url: '/movies',
        templateUrl: 'views/movie.html'
      })
    }
]);

Author:Nitya,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34835492/angular-routing-is-not-working-with-express
Venkat.R :

Add urlRouterProvider to config and Add Controller to stateProvider.state:\n\nmyApp.config(function($stateProvider, $urlRouterProvider) {\n //\n // For any unmatched url, redirect to /state1\n $urlRouterProvider.otherwise(\"/state1\");\n //\n // Now set up the states\n $stateProvider\n .state('state1.list', {\n url: \"/list\",\n templateUrl: \"partials/state1.list.html\",\n controller: function($scope) {\n $scope.items = [\"A\", \"List\", \"Of\", \"Items\"];\n }\n })\n});\n\n\nReference:\nhttps://github.com/angular-ui/ui-router",
2016-01-17T05:59:39
yy