2016-01-06 12 views

risposta

164

Faresti in realtà vogliono solo impostare mode a 'history'.

const router = new VueRouter({ 
    mode: 'history' 
}) 

Assicurarsi che il server sia configurato per gestire questi collegamenti, però. https://router.vuejs.org/en/essentials/history-mode.html

o Se si utilizza Router allora si può usare come

const router = new Router({ 
    mode: 'history', 
    routes: [ 
    { path: '*', component: NotFoundComponent } 
    ] 
}) 

Per Vue 1 uso questo, invece:

const router = new VueRouter({ 
history: 'true' 
}) 
+1

Grazie Bill qui è possibile rimuovere hashbang falsa anche qui è il codice: 'const router = new VueRouter ({ \t cronologia: true }) – DokiCRO

+0

Freddo. Aggiornerò la mia risposta –

+1

Stavo giocando con https://github.com/vuejs/vue-hackernews e aggiungendo '{history: true}' funziona per la prima pagina, ma il resto delle rotte falliva. –

5
window.router = new VueRouter({ 
    hashbang: false, 
    //abstract: true, 
    history: true, 
    mode: 'html5', 
    linkActiveClass: 'active', 
    transitionOnLoad: true, 
    root: '/' 
}); 

e server sia configurato correttamente In apache dovresti scrivere l'url riscrivi

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteRule ^index\.html$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.html [L] 
</IfModule> 
34

Per vue.js 2 utilizzare il seguente:

const router = new VueRouter({ 
mode: 'history' 
}) 
+0

Salvato qui, grazie – TheGeekZn

3

Hash è un'impostazione Vue-router di default, è impostato perché con hash, l'applicazione non ha bisogno di connettersi al server per servire l'url. Per cambiarlo devi configurare il tuo server e impostare la modalità in modalità API cronologia HTML5.

Per la configurazione del server questo è il link per aiutarvi a configurare Apache, Nginx e Node.js server:

https://router.vuejs.org/en/essentials/history-mode.html

Poi si dovrebbe fare in modo, che la modalità router vue è impostato come segue:

versione vue-router 2.x

const router = new VueRouter({ 
    mode: 'history', 
    routes: [...] 
}) 

Per essere chiari, questi sono tutti i modi vue-router si può scegliere: "hash" | "storia" | "Astratto"

1

È necessario configurare il percorso come questo JS vue 2

const router = new VueRouter({ 
    mode: 'history' 
}) 
+0

Esiste già una soluzione funzionante che a differenza delle vostre spiega le soluzioni. Riconsiderare la risposta, pensi di aggiungere dettagli o informazioni importanti alla risposta accettata esistente? –

Problemi correlati