⚠️ This lesson is retired and might contain outdated information.

Set up Vue-Router and add the Root Application Route

Laurie Barth
InstructorLaurie Barth
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 months ago

This lesson goes through vue-router setup from npm install, through the boilerplate code needed to create a router.

Additionally, it creates a single route record for the home page.

Instructor: [00:01] Begin by installing vue-router using npm. We'll use the save flag to automatically add it to our package.json.

[00:12] Now, we'll run our Vue application using the command npm run serve. As we can see, our application is running.

[00:33] In our main.js file, we're going to import VueRouter from 'vue-router.' Next, we'll add 'vue-router to our Vue application with the Vue.use function. We'll create an array of routes that we'll leave empty for the moment.

[00:56] We'll create a new router as an instance of vue-router. In it, we'll add our routes array and we'll set the mode to history. Finally, we'll add our router to our Vue application. In order to see our routing, we need to use the <router-vue> tag which will act as the window in which all of our route components appear.

[01:32] We'll start by creating a route record, which is an object. It requires a path and a component. In this case, we'll set our path to / and we'll use our home component, which we need to import from a pre-existing component page that we've already created.

[01:58] When we refresh, we see that our / path navigates us to our home page, which appears inside the window of the <router-vue> tag we added to our app.vue file.

egghead
egghead
~ 31 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today