2

I face to this problem, I using angular v1.6.5 , my route act weird , let's say I have this route :

 $routeProvider
        .when('/', { templateUrl: 'myTemplate', controller: 'myController', method: 'myMethod' })
}

and my url is like myUrl.com/sectionName what I expect to get is :

myUrl.com/sectionName/#/

but instead I get this :

myUrl.com/sectionName#/

I still can get my data and controllers works fine in this route, but cause some other problems ( for instance cannot detect onhashchange event )

I searched for similar problems but most of them was about some other issues like some extra chars ( like '!' ) which can be fixed by using $locationProvider.hashPrefix(''); and I also already used it in my config, but in my case, the problem is something else.

So if any help on this I will appreciate it.

3
  • 1
    Can you reproduce same problem in jsfiddle using your sample code? It will be easier then to help u. Commented Aug 3, 2017 at 4:29
  • do you have a <base> tag in your HTML? Can you try <base href="sectionName" /> and see if it helps? Commented Aug 5, 2017 at 0:31
  • @Claies Yes I do have it and my base is the root <base href="/"> Commented Aug 5, 2017 at 2:55

1 Answer 1

1
    angular.module('myapp', [])
       .config(function($routeProvider, $locationProvider) {

        $routeProvider
            .when('/', {
                templateUrl : 'partials/home.html',
                controller : mainController
            })
       $locationProvider.html5Mode(true);
});

HTML

<!doctype html>
<html>
<head>
    <meta charset="utf-8">

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

Try this, it will prettify your links.

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

3 Comments

Thanks, I try this but the issue is still there.
wouldn't know exact problem unless you reproduce in jsfiddle.
well can't reproduce it exactly, this is part of a large .NET MVC base web application, I try to reproduce it in an example with same routes in jsfiddle, but it was fine. thanks anyway.

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.