0

I have simple angularjs application and I believe I did not configure the routing the right way because in the browser the url looks weird. For example when I access my index.html page this is the url: http://localhost:8082/basic-web-app/app/index.html#/ and when I navigate to another pages within the app it appends the location after index.html#/: http://localhost:8082/basic-web-app/app/index.html#/login Every example I checked was without index.html and appending the location like http://localhost:8082/basic-web-app/app/ and http://localhost:8082/basic-web-app/app/login My routing:

    coursesApp.config(function($routeProvider, $httpProvider) {
    $routeProvider

    // route for the home page
    .when('/', {
        templateUrl: 'pages/home.html',
        controller: 'mainController',
        controllerAs: 'controller'
    })

    // route for the courses page
    .when('/courses', {
        templateUrl: 'pages/courses.html',
        controller: 'coursesController'
    })

    // route for the courses page
    .when('/login', {
        templateUrl: 'pages/login.html',
        controller: 'loginController',
        controllerAs: 'controller'
    })

    .when('/profile', {
        templateUrl: 'pages/profile.html',
        controller: 'profileController'
    });

    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
});

thank you!

4
  • 1
    your index.html should be outside the app folder. then run your app as, http://localhost:8082/basic-web-app/app Commented Nov 12, 2016 at 7:31
  • Do you mean in the webapp folder? Commented Nov 12, 2016 at 8:43
  • I put it outside app folder another blank index.html file and I am able to load it using localhost:8082/basic-web-app/app. The interesting part is that not the blank index.html is loaded but mine. Any ideas? Commented Nov 12, 2016 at 8:51
  • Thanks for help @Sravan. It worked. I had some wrong configuration Commented Nov 12, 2016 at 9:18

2 Answers 2

1

The issue is your folder structure.

The index.html should be outside of the app folder.

The index.html lives at the root of front-end structure. The index.html file will primarily handle loading in all the libraries and Angular elements.

HEre is an example of folder structure,

app/
----- controllers/
---------- mainController.js
---------- otherController.js
----- directives/
---------- mainDirective.js
---------- otherDirective.js
----- services/
---------- userService.js
---------- itemService.js
----- js/
---------- bootstrap.js
---------- jquery.js
----- app.js

views/
----- mainView.html
----- otherView.html

index.html

Here are some links for your folder structure:

https://johnpapa.net/angular-growth-structure/

https://scotch.io/tutorials/angularjs-best-practices-directory-structure

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

1 Comment

@skywalker, Good to hear your issue solved. I added as an answer, you can vote and accept, if you find it helpful.
0

If I got your question right, then:

There is nothing wrong in what you have done. Every Single Page Application framework (AngularJS being one of those) uses the hash - # - intelligently to keep the user on the same page. As long as your views are rendering the way you need, it looks alright.

Comments

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.