2016-12-06 14 views
6

私はVue Cliとwebpackを使って、背中用のNodeJS/ExpressとFront用のVueJSでアプリケーションを作成しています。VueルータWebpackドットでParams

私のルートのパラメータをドットで許可する方法があるかどうかを知りたいのですが。ここで

は私がいない設定ここ

Cannot GET /t/firstname.lastname

にしようとすると、私も私、私の/src/main.js

import Vue from 'vue' 
import App from './App.vue' 

import VueRouter from 'vue-router' 
import VueResource from 'vue-resource' 
import VueAutosize from 'vue-autosize' 

import Main from './components/Main.vue' 
import Signin from './components/Signin.vue' 

// We want to apply VueResource and VueRouter 
// to our Vue instance 
Vue.use(VueRouter) 
Vue.use(VueResource) 
Vue.use(VueAutosize) 

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

// Pointing routes to the components they should use 
router.map({ 
    '/t/:person': { 
    component: Main 
    }, 
    '/signin': { 
    component: Signin 
    } 
}) 

router.beforeEach(function (transition) { 
    if (transition.to.path === '/signin' && window.localStorage.length !== 0) { 
    transition.redirect('/') 
    } else if (transition.to.path === '/' && window.localStorage.length === 0) { 
    transition.redirect('/signin') 
    } else { 
    transition.next() 
    } 
}) 

// Any invalid route will redirect to home 
router.redirect({ 
    '*': '/404' 
}) 

router.start(App, '#app') 
+1

私はvue-routerがurlのparamをjavascriptオブジェクトに変換するので、ポイントの使用は許可されていないと思います。しかし、私は他の句読点でテストしましたが、大丈夫です。 必要に応じてregexpまたはoptionnalパラメータを使用できます。> [https://github.com/vuejs/vue-router/blob/9649929b3646954c7b59d149c570c3d0a96379c9/examples/route-matching/app.js](https://github.com/) vuejs/vue-router/blob/9649929b3646954c7b59d149c570c3d0a96379c9/examples/route-matching/app.js) –

+0

@utiiz解決策を見つけましたか?私は同じ問題を抱えています。 –

+0

これはWebpackとどのように関連していますか? –

答えて

1
私は同じ問題を扱った

され得るものです会話に遅れていると、誰かが私が見つけた解決策を見つけるかもしれない。

ウェブパックの不具合のようです。

vue-cliのwebpackテンプレートを使用する場合は、必要なルートのプロキシを設定する必要があります。そのURLへのすべての要求こうWebPACKの意志プロキシ

... 
dev: { 
    ... 
    proxyTable: { 
    '/t/*.*': { // this will match all urls with dots after '/t/' 
     target: 'http://localhost:8080/', // send to webpack dev server 
     router: function (req) { 
     req.url = 'index.html' // Send to vue app 
     } 
    } 
    // Any other routes you need to bypass should go here. 
    } 
    ... 
}, 
... 

およびファイルとしてこれらを扱うことはありません:たとえば、あなたのケースで、あなたはconfig/index.jsファイルにこれを追加する必要があります。