0

I have a basic single page application in Angular Js. I have applied routing and set 'Html5Mode' to true.

My URL's have been cleaned up, but they now result in a 404 when trying to access the URL.

Now this is a front end web application so I do not have any config on IIS I can set up rewrite rules with.

Can anyone point me in the right direction to set up the URL's to prevent 404 error.

Below is my routing:

(function () {
"use strict";

angular.
    module("app", [
        "ngRoute",
        "app.home",
        "app.products",
        "app.contact"
    ])

.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when("/",
        {
            controller: "HomeController",
            templateUrl: "app/components/home/home.html"
        })
        .when("/products",
        {
            controller: "ProductsController",
            templateUrl: "app/components/products/products.html"
        })
        .when("/contact",
        {
            controller: "ContactController",
            templateUrl: "app/components/contact/contact.html"
        })
        .otherwise("",
        {
            controller: "HomeController",
            templateUrl: "app/components/home/home.html"         
        });


        $locationProvider.html5Mode(true);

    });

})();

Index.html:

 <!DOCTYPE html>
 <html ng-app="app" lang="en">
 <head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">

<title>Newtown Gates & Welding</title>

<link href="assets/css/site.css" rel="stylesheet" />
<link href="app/components/home/home.css" rel="stylesheet" />
<link href="app/components/contact/css.css" rel="stylesheet" />
<link href="app/components/products/products.css" rel="stylesheet" />
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap-theme.css" rel="stylesheet" />

<script src="assets/libs/angularjs/1.6.1/angular.js"></script>
<script src="assets/libs/angularjs/1.6.1/angular-route.js"></script>

<script src="app/app.js"></script>
<script src="app/components/home/homeController.js"></script>
<script src="app/components/products/productsController.js"></script>
<script src="app/components/contact/contactController.js"></script>
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/bootstrap.min.js"></script>


<base href="/"/> <!--Required when using location provider-->

<div>
    Navbar here

    <li>
        <a href="/">home</a>
        <a href="/contact">contact</a>
        <a href="/products">products</a>
    </li>

</div>

<div class="container-fluid">

    <div class="row" style="border: 1px solid black;">
        HELLO
    </div>

    <div ng-view></div>

  </div>
 </body>
 </html>
7
  • what is the path it shows? Commented Jan 15, 2017 at 13:29
  • it does not show any error Commented Jan 15, 2017 at 13:40
  • from the home page you can access /products. Either try to access this or refresh the page. @Sajeetharan Commented Jan 15, 2017 at 13:41
  • i did the same, it gets routed to products and i see the content as I don't see no dahm products! Commented Jan 15, 2017 at 13:42
  • ok, well try and access josephaspey.com/products Commented Jan 15, 2017 at 13:45

1 Answer 1

0

Please add <base href="/" /> to your <head>

Please look here:

link

EDIT

you need to set the current folder in my case is enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, I have does this. I will edit my answer to show this.
Hi, edit my answer to your edit, please tell me if its work for you @ClarkySmiverz77
index.html is at the root of my project, so '/' is correct.
Ok, so index.html is at the route of the project. the rest of the pages are as follows "app/components/x/x.html"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.