I have an app where I load component using <router-view/>
!
I am getting the problem in importing the component in router.js
. It always gives me the following error:
These relative modules were not found:
* ./components/Poetry.vue in ./src/router/routes.js
* ./components/PoetryDetails/PoetryCard.vue in ./src/router/routes.js
* ./components/PoetryDetails/Search.vue in ./src/router/routes.js
I have the folder structure like this:
├── _components
| ├── _PoetryDetails
| | └──PoetryCard.vue
| | └──Search.vue
| └── Poetry.vue
├── _router
| ├── index.js (routes.js is imported in this file)
| └── routes.js
├── App.vue
└── main.js
In routes.js
, I am importing the components as follows:
import Poetry from './components/Poetry.vue'
import PoetryCard from './components/PoetryDetails/PoetryCard.vue'
import PoetrySearch from './components/PoetryDetails/Search.vue'
export const routes = [
{ path: '', name: 'poetrysearch', component: Poetry, children: [
{ path: 'poetry', name: 'poetrycard', component: PoetryCard },
{ path: 'poetry/search', name: 'poetrysearch', component: PoetrySearch },
]},
]
But, I am still getting the damn error. Please help.
You're using relative path. In your routes.js
, it should be
import Poetry from '../components/Poetry.vue'
import PoetryCard from '../components/PoetryDetails/PoetryCard.vue'
import PoetrySearch from '../components/PoetryDetails/Search.vue'
..
notation means go to parent folder.
If you're using webpack, you can add alias:
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
...
'@': resolve('src'), // your source folder
}
}
and then you can import:
import Poetry from '@/components/Poetry.vue'
import PoetryCard from '@/components/PoetryDetails/PoetryCard.vue'
import PoetrySearch from '@/components/PoetryDetails/Search.vue'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With