2016-03-01 3 views
6

mio URL assomiglia a questo http://127.0.0.1:50884/index.html#/homecome rimuovere tag cancelletto (#) dall'indirizzo URL in ui-router

Questa la pagina indice. Sto usando angolare ui-router di cambiare per varie viste come ma url viene fornito con tag # come questo: http://127.0.0.1:50884/index.html#/mobileOperator http://127.0.0.1:50884/index.html#/contentExpertise

Domanda: Esiste un modo per rimuovere # tag/pulita dal url .. per mostrare la sentiero URL come qui di seguito:

http://127.0.0.1:50884/index.html/home

http://127.0.0.1:50884/index.html/contentExpertise

ho provato html5mode ma dà errore angolare in consolle.

Error: [$location:nobase] http://errors.angularjs.org/1.5.0-rc.2/$location/nobase 
K/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:6:421 
pf/this.$get<@http://127.0.0.1:50884/js/angular-v1.5.min.js:110:96 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 
gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 
gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 
gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:1 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:86 
s/</<@http://127.0.0.1:50884/js/angular-v1.5.min.js:52:121 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:7:364 
s/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:52:90 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 
e/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:38:458 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 
gb/F<@http://127.0.0.1:50884/js/angular-v1.5.min.js:43:96 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:40:270 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:71:447 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:60:266 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:58:229 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:58:397 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:58:397 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:56:263 
Ac/c/</<@http://127.0.0.1:50884/js/angular-v1.5.min.js:21:99 
sf/this.$get</[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:140:363 
sf/this.$get</[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:141:83 
Ac/c/<@http://127.0.0.1:50884/js/angular-v1.5.min.js:21:57 
h/<[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:41:293 
Ac/[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:20:1 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:21:274 
[email protected]://127.0.0.1:50884/js/angular-v1.5.min.js:20:83 
@http://127.0.0.1:50884/js/angular-v1.5.min.js:306:372 
n.Callbacks/[email protected]://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:27060 
n.Callbacks/[email protected]://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:27828 
[email protected]://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:29619 
[email protected]://127.0.0.1:50884/js/jquery-2.2.1.min.js:2:29804 
" 

Si prega di aiutare

+0

Vedere questo :) http://stackoverflow.com/questions/28388860/angular-add-slash-before-hash-in-url/28388903#28388903 –

+0

utilizzare questo :: $ locationProvider.html5Mode (true); –

risposta

11

Per impostazione predefinita, AngularJS sarà indirizzare gli URL con un hashtag. È molto facile ottenere URL puliti e rimuovere l'hashtag dall'URL utilizzando $locationProvider in AngularJS. È necessario inserire $locationProvider nella sezione di configurazione del modulo e utilizzare l'API di cronologia HTML5 in questo modo. ad es.

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) { 
    $stateProvider 
     .state('home', { 
      url: '/home', 
      templateUrl: 'partial-home.html' 
     }) 
     .state('about', { 
      url: '/aboutus', 
      templateUrl: 'aboutus.html' 
     }); 
    $locationProvider.html5Mode(true); 
}); 

Inoltre, non dimenticare di mettere un tag <base href="/"> all'interno della sezione index.html.

+0

ora il mio url sembra http://127.0.0.1:49625/home ma dopo averlo aggiunto se premo refresh ricevo il messaggio ' Impossibile ottenere/home 'anche se torno indietro di nuovo lo stesso messaggio dire da un altro URL anche. – Sam

+0

Ora hai bisogno di riscrivere il tuo URL. Fammi sapere quale tecnologia lato server stai usando con angularJS –

+0

sono sul server locale usando parent.io. ed ecco il git repo https://github.com/vipul-verma/naysa – Sam

2

Affinché la modalità HTML5 di lavorare è necessario definire una baseurl come:

<base href="whatever/" /> 

Vedi w3schools per ulteriori informazioni: http://www.w3schools.com/tags/tag_base.asp

+0

mi aiuta per il tuo ** qualunque ** nel nostro caso era 'base_url()' –