문제

I want to build a single page application with angular.js the only thing is i want a traditional url structure.

Example:

  Before: www.example.com/#/index  
  After:  www.example.com/index  

  Before: www.example.com/#/user/21345678  
  After:  www.example.com/user/21345678  

First of all is it possible?
Second how would i do that?
Any server except Apache XD

도움이 되었습니까?

해결책

You need to enable HTML5 mode within angular.

.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true).hashPrefix('!');

Then you also need to configure your sever. See this article: Configure your server to work with html5Mode

I'd suggest reading this short post: Pretty URLs in Angular, Removing the Hashtag. In it they also recommend setting <base href="/"> within the head of your HTML.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top