DEV Community

sh-web-lee
sh-web-lee

Posted on

What are the differences between the following two methods?

What are the differences between the following two methods, please?
eg1: const router = new vueRouter({...}) export default router

eg2: export const router = new vueRouter({...})

Discussion (2)

Collapse
sargalias profile image
Spyros Argalias

First one is a default export. You can import it in another file with any name you like. For example, foo, bar, anythingYouWant, etc.

Example:

import thisCanBeNamedAnythingYouWant from './path/to/file';
Enter fullscreen mode Exit fullscreen mode

The bottom one is a named export. It's missing the keyword default. You need to import that one with the correct name and with curly braces, like this:

import {router} from './path/to/file';
Enter fullscreen mode Exit fullscreen mode

More information at: developer.mozilla.org/en-US/docs/w...

Collapse
shweblee profile image
sh-web-lee Author

thank u. ok, I got it. So this is why I can't use 'router' in another JS file when I did as same as method 2