Use vue-router to set the title method for each page.

Source: Internet
Author: User

Use vue-router to set the title method for each page.

Basic Environment configuration: webpack + vue2.0 + vue-router + nodeJS

Go to the index. js file under the router folder.

First introduce:

import Vue from 'vue'import Router from 'vue-router'

Then configure the address of each route in the route:

Routes: [{/* (homepage) default route address */path: '/', name: 'enables', component: Entrance, meta: {title: 'homepage entry '}},{/* modify nickName */path:'/modifyName/: nickname', name: 'modifyname', component: modifyName, meta: {title: 'modify nickname '}, {/* product details */path:'/goodsDetail ', name: 'goodsdetail', component: goodsDetail, meta: {title: 'item details' }},{/* Not Found route, must be the last route */path: '*', component: NotFound, meta: {title: 'page not found '}]

Set the title name of the page in each meta.

Router. beforeEach (to, from, next) =>{/* modify the page title */if (. meta. title) {document. title =. meta. title} next ()})

In this way, the title is added to every VUE page.

The above method of setting the title of each page by using vue-router is all the content shared by Alibaba Cloud. I hope you can give us a reference and support for the customer's house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.