1

I am using ui-router in my angularjs app inside a website project in Visual Studio, but it only works with the route http://localhost/index.html#!/my-page, but I want the route to be only http://localhost/my-page.

Is there a way to do this?

Here is my routing code:

angular.module('nutricaoApp').config(function ($stateProvider, $urlRouterProvider, $locationProvider, $urlMatcherFactoryProvider) {
    $urlMatcherFactoryProvider.caseInsensitive(true);

    $urlRouterProvider.otherwise('cardapio-paciente');

    $stateProvider
    .state('my-page', {
        url: '/my-page',
        templateUrl: './app/components/my-page.html',
        controller: 'MyPageController'
    });

  $locationProvider.html5Mode(false);
});

1 Answer 1

3

You can try:

app.config(["$locationProvider", function($locationProvider) {
  $locationProvider.html5Mode(true);
}]);

<base href="/">

How to delete '#' sign in angular-ui-router URLs

And config your .htaccess to remove index.html

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

Working example on codepen

https://codepen.io/centrodph/pen/gXGVvz?editors=1010

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

6 Comments

It works when I am routing on angularjs, but when I enter the url manually on the browser, it doesn't works.
I thinks you can fix that with a .htaccess rule
At now, I am not doing any back-end on my application, this rule could be applied to that case?
Yes you can upload your .htaccess file on your root folder. The .htaccess rules will apply to the all site.
But I've been thinking, will angular always make my url look like "www.mysite.com/index.html/my-page.html" by default?
|

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.