ngRoute does not work

1

I was trying to use ngRoute, but I enter the link '/ new', an error appears that does not exist that URL and when I enter the normal '/', it does not show anything.

The index.html:

<html ng-app="starter">
<head>
    <title>App</title>      
    <link rel="icon" href="m/src/logo.ico" type="image/x-icon">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta content="width=device-width" initial-scale="1.0" maximum-scale="1.0" user-scalable="0" name="viewport">
    <meta name="viewport" content="width=device-width">
    <script type="javascript/text" src="m/lib/angular.js"></script>
    <script type="javascript/text" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular-route.min.js"></script><scripttype="javascript/text" src="m/js/app.js"></script>
    <script type="javascript/text" src="m/js/controller.js"></script>   
</head>

<body>
    <div ng-view></div>
</body>

The app.js

var app = angular.module("starter", ["ngRoute"]);

app.config(function ($routeProvider, $locationProvider) {

    $locationProvider.html5Mode(true);

    $routeProvider
        .when("/", {
            templateUrl: "templates/main.html"
        })
        .when("/new", {
            templateUrl: "templates/news.html"
        })
        .otherwise({
            redirectTo: "/"
        });
});
    
asked by anonymous 14.04.2017 / 18:42

1 answer

0

You are setting the Angle to use HTML5 mode:

$locationProvider.html5Mode(true);

You then need to set the value of base in the header of your page - for example:

<head>
    <base href="/">
</head>

And also be sure that you will need to map the destination URLs to the base, and this will depend on the type of server you are using. In IIS, for example, you can use UrlRewrite .

    
14.04.2017 / 21:44