I searched and I found "solutions" to this problem, but I still cannot get it to work correctly.
Scenario:
I create an Angular website (version 1.2) using a UI router and run it on the Node server on localhost. I am trying to make it a “pretty” url with $ locationProvider and turning html5 (true). My site works fine when I click on it, but when I try to go to the relative link path or update the link path, the page breaks. I also intend to deploy this webapp to Heroku upon completion:
RELATIVE COMMUNICATION:
http:
PAGE OUTPUT RESULT
Cannot GET /locksmith-services
The steps I took:
1.) In my "index.html" <head>, I set my base url to:
<base href="/"></base>
2.) In my app.js file (for Angular), I wrote it as follows:
// App Starts angular .module('app', [ 'ui.router', 'ngAnimate', 'angular-carousel' ]) .config(['$urlRouterProvider', '$stateProvider', '$locationProvider', function($urlRouterProvider, $stateProvider, $locationProvider) { $urlRouterProvider.otherwise("/"); $stateProvider .state('home', { url: '/', templateUrl: 'pages/home.html', controller: 'homeCtrl' }) .state('services', { url: '/locksmith-services', templateUrl: 'pages/locksmith-services.html', controller: 'servicesCtrl' }) .state('locations', { url: '/locksmith-locations', templateUrl: 'pages/locksmith-locations.html' }) .state('payment', { url: '/locksmith-payment', templateUrl: 'pages/locksmith-payment.html' }) // use the HTML5 History API $locationProvider.html5Mode(true); }])
3.) In my navigation I have html written as:
<div class="wrapper"> <a ui-sref="home"> <img src="images/logo.png" class="logo" alt="Austin Texas Locksmith" /> </a> </div> <nav class="row navigation"> <a class="mobile33" ui-sref="services" ui-sref-active="active" class="active">Services</a> <a class="mobile33" ui-sref="locations" ui-sref-active="active">Locations</a> <a class="mobile33" ui-sref="payment" ui-sref-active="active">Payment</a> </nav>
4.) My file server.js (node server)
var express = require('express'); var app = express(); app.use(express.static(__dirname + '/front')); var port = process.env.PORT || 8000; app.listen(port);
What would be the best solution? Thanks in advance for your help.