I'm building a webapp using ui-router
for AngularJS to handle my routing through $stateProvider
so that only the various states gets rendered in the ui-view
.
I have a server.js
file hoping to render an initial scaffolding (top-nav, footer..etc.) which the web app is going to based on, and I want all request to be loaded with this template and populate each individual page using templates.
However, I keep getting ERROR: Cannot find module 'html'
.
I've dug through stackoverflow and also tried installing EJS so that I can render my index.html page, but it still didn't work.
What would be the best way to serve up a static html template and have angular ui-router do the rest of the routing?
Here are the two files:
server.js
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var routes = require('server/routes');
// Set Port
var PORT = process.env.PORT || 3000;
// Rendering configuration
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(bodyParser.json());
routes(app);
app.get('/*', function(req,res) {
res.render('index.html');
});
app.listen(PORT, function() {
console.log('Server running on ' + PORT)
});
config.js
import angular from 'angular';
import uiRouter from 'angular-ui-router';
// Factories
import todoFactory from 'factories/todo-factory';
// Controllers
import todosController from 'controllers/todosController';
import profileController from 'controllers/profileController';
import signupController from 'controllers/signupController';
import signinController from 'controllers/signinController';
const app = angular.module('airporter', [uiRouter, todoFactory.name]);
app.config(($stateProvider, $urlRouterProvider, $locationProvider) => {
$urlRouterProvider.otherwise('/');
$stateProvider
// Homepage
.state('home', {
url: '/',
templateUrl: 'views/index.html',
})
// Sign Up
.state('signup', {
url: '/signup',
templateUrl: 'views/signup/signup.html',
controller: signupController
})
// Sign In
.state('signin', {
url: '/signin',
templateUrl: 'views/signin/signin.html',
controller: signinController
})
//
.state('profile', {
url: '/profile',
templateUrl: 'views/profile/profile.html',
controller: profileController,
resolve: {
// logincheck: checkLoggedin
// if the following dependencies are successfully resolved you can access profile
}
})
.state('todos', {
url: '/todos',
templateUrl: 'views/todos/todos.html',
controller: todosController
})
.state('about', {
url: '/about',
templateUrl: 'views/about/about.html'
});
$locationProvider.html5Mode(true);
});
export default app;