0

I am devveloping a website using angularjs in which only 1 html page is present. I want to show the record by giving record Id from url as abc.in/1. When I try to give this Id from url, it gives 404 not fount error. But when I give abc.in#1 it works fine and displays the record. I tried

angular.module('myApp', [
      'ngRoute', 'ngResource', 'ngCookies',
      'myApp.filters',
      'myApp.services',
      'myApp.directives',
      'myApp.controllers',
      'ui.bootstrap', 'ngAnimate', 'ngDragDrop'  //'ngSanitize',
    ]).
    config(['$routeProvider','$locationProvider', function ($routeProvider,$locationProvider) {

     $routeProvider.when('/',
          {
              templateUrl: '/Login.html',
              controller: 'LoginController'
          });

        $routeProvider.when('/:id',
          {
              templateUrl: '/Login.html',
              controller: 'LoginController'
          });

        $routeProvider.otherwise({ redirectTo: '' });

    if (window.history && window.history.pushState) {
                    $locationProvider.html5Mode({
                    enabled: true,
                    requireBase: false
                });                    
            }

in my app.js and in Login.html (which is default and only page in my application) is as-

<base href="/">

in head tag.

But this will only converts abc.in#1 to abc.in/1 when I try to refresh the page it will give error as-

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

As per the given code I first need to give #1 in url and then it will converts into /. But I want to give /1 initially. How to do that?

Sayli Vaidya
  • 179
  • 1
  • 14
  • I thinking about `domain.com/#/:id` -> `domain.com/#/1` which will be a angular route. domain.com/1 isn't a angularJS route. Why you need a `base`set in the head? – lin May 14 '15 at 09:54
  • `domain.com/1` is the requirement. Can we do that? – Sayli Vaidya May 14 '15 at 10:48
  • No, its not supported because of: http://caniuse.com/#feat=history -> http://stackoverflow.com/questions/14319967/angularjs-routing-without-the-hash – lin May 14 '15 at 11:15
  • Is there any other way to that? I tried it using a simple ajax call too. but it also requires `#` to display result. Here is the reference - [http://stackoverflow.com/questions/30237437/extract-data-from-current-url-and-use-it-in-ajax-call-as-a-paramenter?noredirect=1#comment48576943_30237437] – Sayli Vaidya May 15 '15 at 04:34
  • Why are you using AJAX in angularJS? – lin May 15 '15 at 07:32
  • I am not using ajax in angularjs. I am trying to get data by ajax from seperate website project which contains only `Login.html` page and ajax call in it to get data. – Sayli Vaidya May 15 '15 at 09:00
  • Iam totally confused. So its not an angularJS problem? – lin May 15 '15 at 10:16

0 Answers0