Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclamation mark after hash (#!) in angularjs app

Tags:

angularjs

I have just noticed that I have an exclamation mark after a hash (#!) in all of my routes. I'm not sure how and why I got them because earlier today I didn't have them.

If there is any solution to get rid of them, I would appreciate if someone can explain me what is it( and how I came to have them).

So, the only solution that I have found so far is to put manually put the exclamation mark on every href in my app, but this annoys me and I have no idea what to do.

I generated my app with yeoman generator and my app.js looks like this:

angular
  .module('appNameApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl',
        controllerAs: 'main'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'AboutCtrl',
        controllerAs: 'about'
      })
      .when('/jaspo', {
        templateUrl: 'views/about.html',
        controller: 'jaspoCtrl',
        controllerAs: 'vm'
      })
      .otherwise({
        redirectTo: '/'
      });
  });
like image 474
Sahbaz Avatar asked Dec 19 '16 00:12

Sahbaz


People also ask

What is the exclamation point in URL?

2. Not Secure Site Icons. Sites that are not fully secure and still use HTTP are shown up by the Grey circle with an exclamation point inside. This means that the site is not using a private connection as it does not have a security certificate.

What does this symbol mean exclamation point?

The exclamation mark, !, or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, for example: "Watch out!".

What does exclamation mark before variable mean?

If you have ever noticed a double exclamation mark (!!) in someone's JavaScript code you may be curious what it's for and what it does. It's really simple: it's short way to cast a variable to be a boolean (true or false) value.

What does exclamation mark mean in the UK?

The exclamation mark is used to express exasperation, astonishment, or surprise, or to emphasise a comment or short, sharp phrase.

What does the hash and exclamation mark in a URL mean?

The hash and exclamation mark in a url are called a hashbang, and are usualy used in web applications where javascript is responsible for actually loading the page. Content after the hash is never sent to the server. So for example if you have the url example.com/#!recipes/bread.

How to use the exclamation mark (!) to execute specific commands?

We can use the exclamation mark (!) to execute specific commands from the history. 4.1. Execute the Previous Command $ echo 'Hello, World' Hello, World $ !! echo 'Hello, World' Hello, World 4.2. Execute the N th Command

What does exclamations mean in HTML?

EXCLAMATION MARK (HTML ! · !) ǃ The exclamation mark, !, also sometimes referred to as the exclamation point, especially in American English, is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings, or to show emphasis.

What do exclamations mean on a warning sign?

Warning signs are often an exclamation mark enclosed within a triangle. Exclamation marks are used to emphasize a precautionary statement. On warning signs, an exclamation mark is often used to draw attention to a warning of danger, hazards, and the unexpected.


3 Answers

Modify these 2 lines :

  .config(function ($routeProvider) {
$routeProvider

to be :

    .config(function ($routeProvider,$locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider

Credit should go to : https://stackoverflow.com/a/41223197/1564146

like image 169
Skrew Avatar answered Nov 10 '22 00:11

Skrew


You probably updated angular version from 1.5 to 1.6, because on 1.6, the angular team decided to change the default $location hash-prefix to '!'. Like @Skrew suggested, you can change that to '' with $locationProvider.hashPrefix('');

Here you can read about that.

like image 24
Sheki Avatar answered Nov 10 '22 01:11

Sheki


Your function is missing a locationProvider and needs to specify html5Mode for the locationProvider. See https://docs.angularjs.org/api/ng/provider/$locationProvider. Instead of:

.config(function ($routeProvider) { $routeProvider .when('/', {

try:

.config(function ($locationProvider, $routeProvider) { $locationProvider.html5Mode({ enabled:true }); $routeProvider .when('/',{

By default you also need to specify a base tag <base href="/"> in your index.html file.

like image 35
wanyo Avatar answered Nov 09 '22 23:11

wanyo