Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs Error: [$location:nobase]

Tags:

angularjs

y try to create a simple web with angular Project asp.net mvc 5 i have this js

var app = angular.module("app", ["ngRoute"])
    .config(function ($routeProvider, $locationProvider) {
        $routeProvider.when('/', {
            templateUrl: '/AngularJS/Templates/inicio.html',
            controller: 'bienvenidoController'
        });
        $locationProvider.html5Mode(true);
    });

and this:

app.controller("bienvenidoController", function ($scope) {

});

view: Layout:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
</head>
<body ng-app="app">
    @RenderBody()
    <!--Librerias Angular-->
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/angular-route.min.js"></script>

    <!---Librerias App-->
    <script src="~/AngularJS/RegistrationModule.js"></script>
    <script src="~/AngularJS/bienvenidoController.js"></script>
</body>
</html>

index:

<div ng-view>

</div>

and:

<h1>Hola Mundo!</h1>

error:

Error: [$location:nobase]

error see in firebug mozilla

like image 690
Pedro Luis Antonio Miranda Avatar asked Aug 19 '15 14:08

Pedro Luis Antonio Miranda


2 Answers

As stated on the AngularJs documentation

If you configure $location to use html5Mode (history.pushState), you need to specify the base URL for the application with a tag or configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode()

https://docs.angularjs.org/error/$location/nobase

You are missing the <base href="/"> in your document or you can disable the check by setting

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});
like image 199
Mike Vranckx Avatar answered Oct 23 '22 13:10

Mike Vranckx


Just add <base href="/"> in the <head> section of HTML document and that's it.

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

https://docs.angularjs.org/error/$location/nobase

like image 1
Friend Avatar answered Oct 23 '22 14:10

Friend