Nuxtについて学習中です。
パラメータを利用してNuxtアプリにアクセスしようとすると
「This page could not be found」の画面になってしまいます。
原因や解決方法などご教示していただけると助かります。
ターミナルやブラウザ画面にはエラーログなどは表示されていないので、解析が難しい状況です。
アクセスできないファイル
URL「http://localhost:9000/p/hanako/flower」
ファイル「pages/p/_id/_pass.vue」
_pass.vue
1<template> 2 <section class="container"> 3 <h1>{{title}}</h1> 4 <p v-html="message">no message</p> 5 <hr> 6 <div class="right"> 7 <router-link to="/">Go to Top</router-link> 8 </div> 9 </section> 10</template> 11 12 13<script> 14export default { 15 data: function() { 16 return { 17 title: "login", 18 }; 19 }, 20 computed: { 21 message: function() { 22 let id = this.$route.params.id != undefined 23 ? this.$route.params.id : "*** no id ***"; 24 let pass = this.$route.params.pass != undefined 25 ? this.$route.params.pass : "*** no password ***"; 26 return "ID:" + id + "<br>PASS:" + pass; 27 }, 28 }, 29} 30</script> 31 32<style> 33 34略 35 36</style>
アクセスできるファイル
URL「http://localhost:9000」
ファイル「pages/index.vue」
index.vue
1<!-- Please remove this file from your project --> 2<template> 3 <section class="container"> 4 <h1>{{title}}</h1> 5 <p>{{message}}</p> 6 <hr> 7 <router-link to="/other">go to other</router-link> 8 </section> 9</template> 10 11<script> 12export default { 13 name: 'NuxtTutorial', 14 data: function() { 15 return { 16 title: "Hello", 17 message: "this is message.....", 18 now: "wait...", 19 }; 20 }, 21 created: function() { 22 setInterval(() => { 23 var d = new Date(); 24 this.now = d.getHours() 25 + ':' + d.getMinutes() 26 + ':' + d.getSeconds(); 27 }, 1000); 28 }, 29}; 30</script>
その他設定ファイル
「.nuxt/router.js」に今回のファイルへのルーティングが設定されていない?
前に作成したindex.vue、other.vueは設定されている
router.js
1const _c51c026c = () => interopDefault(import('../pages/other.vue' /* webpackChunkName: "pages/other" */)) 2const _3d6810e8 = () => interopDefault(import('../pages/index.vue' /* webpackChunkName: "pages/index" */)) 3 4const emptyFn = () => {} 5 6Vue.use(Router) 7 8export const routerOptions = { 9 mode: 'history', 10 base: '/', 11 linkActiveClass: 'nuxt-link-active', 12 linkExactActiveClass: 'nuxt-link-exact-active', 13 scrollBehavior, 14 15 routes: [{ 16 path: "/other", 17 component: _c51c026c, 18 name: "other" 19 }, { 20 path: "/", 21 component: _3d6810e8, 22 name: "index" 23 }], 24 25 fallback: false 26}
「.nuxt/routes.json」も同様
routes.json
1[ 2 { 3 "name": "other", 4 "path": "/other", 5 "component": "/workspace/pages/other.vue", 6 "chunkName": "pages/other", 7 "_name": "_c51c026c" 8 }, 9 { 10 "name": "index", 11 "path": "/", 12 "component": "/workspace/pages/index.vue", 13 "chunkName": "pages/index", 14 "_name": "_3d6810e8" 15 } 16]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。