1

I'm experiencing a problem with my code.

When refreshing the page on localhost:portnumber/home or /todos or /contacts it crash ->

with replay Cannot GET /home or /todos or /contacts.

same problem if i just enter localhost:portnumber/blablabla ->

replay with Cannot GET /blablabla

but if i enter just localhost:portnumber it replay with localhost:portnumber/home which it good !

I need to fix the refresh problem and the Unknown path

my ngRoute code :

angular.module('contactsApp' , ['ngRoute', 'ngMessages'])
/*
    ROUTE configuration
    when href is... do...
*/
.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when('/contacts', {
            controller: 'listCtrl',
            templateUrl: '/views/list.html'
        })
        .when('/contacts/new', {
            controller: 'newCtrl',
            templateUrl: '/views/new.html'
        })
        .when('/contact/:id', {
            controller: 'editCtrl',
            templateUrl: '/views/edit.html'
        })
        .when('/todos', {
            controller: 'todoCtrl',
            templateUrl: '/views/noteslist.html'
        })
        .when('/home', {
            controller: 'homeCtrl',
            templateUrl: '/views/Home.html'
        })
        .otherwise({redirectTo: '/home'});
    $locationProvider.html5Mode(true);
});

my index.html:

<html ng-app="contactsApp">
<head>

    <base href="/">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="src/css/style.css" type="text/css">
    <link href="src/css/landing-page.css" rel="stylesheet">

    <!-- Bootstrap Core CSS -->
    <link href="src/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>

    <!-- Navigation bar -->
    <nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
        <div class="container topnav example2">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/home"><img src="images/logo_noback.jpg" alt="My Office" height="40px" width="auto"/></a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right increse-font-17">
                    <li>
                        <a href="home">Home</a>
                    </li>
                    <li>
                        <a href="todos">ToDo</a>
                    </li>
                    <li>
                        <a href="contacts">Contacts</a>
                    </li>
                </ul>
            </div>
        </div>   
    </nav>
    <!-- End Navigation bar -->

    <!-- Changed page contact -->
    <div class="navbar-overlap">
        <div ng-view></div>
    </div> 
    <!-- End Changed page contact -->

    <!-- Sticky footer -->
    <footer class="navbar navbar-default navbar-fixed-bottom topnav footer-backcolor">
        <div class="col-md-12 margin-5">
            <p class="col-md-6 breadcrumb visible-md visible-lg">Copyright &copy; My Office 2016. All Rights Reserved</p>
            <ul class="pull-right breadcrumb visible-md visible-lg">
                    <li><a href="/home">Home</a></li>
                    <li><a href="/todos">Todo</a></li>
                    <li><a href="/contacts">Contacts</a></li>
            </ul>
        </div>
    </footer>
    <!-- End Sticky footer -->

    <script src="src/js/jquery.js"></script>
    <script src="src/js/bootstrap.min.js"></script>
    <script src="lib/angular/angular.min.js"></script>
    <script src="lib/angular/angular-route.min.js"></script>
    <script src="lib/angular/angular-messages.min.js"></script>
    <script src="src/js/app.js"></script>
    <script src="src/js/controller.js"></script>
    <script src="src/js/filters.js"></script> 
    <script src="src/js/derectives.js"></script> 
</body>

Shon Otmazgin
  • 23
  • 1
  • 5
  • how do you define you root path of the application? I notice that the urls of your ressources are difined with related url path. Are you sure that your ressouces(js and css) are well charged? – Qianyue Apr 12 '16 at 16:00
  • You really need to specify what server side solution you intend on using? – furkick Apr 13 '16 at 07:39
  • currently i'm not using a server side only the client side, in the future i will use nodeJs – Shon Otmazgin Apr 13 '16 at 16:30

1 Answers1

0

The bug is not in your angular application: it's because you are using html mode for client-side url rewriting.

When doing that, you also need to rewrite the URLs server side to avoid serving 404s when the user hits F5, or manually enters the URL of a page.

This question is for the same issue, with a NodeJS server AngularJS html5mode reloading page

Community
  • 1
  • 1
Eloims
  • 5,106
  • 4
  • 25
  • 41