What is vue's navigation link component?
Vue’s navigation link component is “router-link”. The "
" component supports users to click to navigate in applications with routing functions and specify the target address through the to attribute. The syntax is " ...-link>"; the default rendering is the "" tag with the correct connection, and other tags can be generated by configuring the tag attribute.
The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.
Vue’s navigation link component is “router-link”.
vue component router-link introduction
Where is router-link?
The router-link in the main page shown here
So it is in App.vue (why is the main page written in In App, shouldn't it be written in index.html? No no no, here is to render the content obtained from this page to the main page) [Related recommendations: vuejs introductory tutorial, web front-end 】
Write it wherever you like in App.vue
##How to use router-link
- You need to create the corresponding components
- You need to Write the corresponding routing address of your component
- Write the corresponding (link) on the App.vue page
on the App.vue page
<router-link to="/">Home</router-link>
- The to in this must be consistent with the path you specify, and is not case-sensitive
- Additional: a tag is not allowed, because It reopens a tab, and it can also achieve that effect, but it doesn’t feel as friendly as router-link
Extended knowledge: router- Attributes of link
1, to (required parameter): type string/location
represents the link of the target route. The value can be a string or It is a dynamically bound object that describes the target locationThe following examples//下面是字符串的形式 <router-link to="home">Home</router-link> //下面几种为动态绑定,v-bind: 可以简写为: <router-link :to="'index'">Home</router-link> /*但注意这个组件的导出需要有类似下面的代码 export default { name: 'App', data(){ return { index:'/' } } } */ <router-link :to="{ path: '/home' }">Home</router-link> /* 这个路径就是路由中配置的路径 */ <router-link :to="{ name: 'User'}">User</router-link> /* 在路由的配置的时候,添加一个name属性,例如: routes: [ { path:'/home', name:'User', component:home } ] */
2, tag
Type: stringDefault value: "a"If you want<router-link :to="'index'" tag="li" event="mouseover">Home </router-link>
<router-link :to="{name:'Home'}" tag="li"> <a>Home</a> </router-link>
3, active-class
Type: stringDefault value: "router-link-active"Set the link The CSS class name to use when activating. The default value can be configured globally via the route's construction option linkActiveClass.<router-link :to="{path:'/about'}" active-class="activeClass" >about</router-link>
export default new Router({ mode:'history', linkActiveClass:'is-active', routes: [ { path:'/about', component:about } ] })
4, exact-active-class
type: stringDefault value: "router-link-exact-active"配置当链接被精确匹配的时候应该激活的 class。注意默认值也是可以通过路由构造函数选项 linkExactActiveClass 进行全局配置的。
5、exact
类型: boolean
默认值: false
"是否激活" 默认类名的依据是 inclusive match (全包含匹配)。 举个例子,如果当前的路径是 /a 开头的,那么
按照这个规则,每个路由都会激活
<li><router-link to="/">全局匹配</router-link></li> <li><router-link to="/" exact>严格匹配</router-link></li>
简单点说,第一个的话,如果地址是/aa,或/aa/bb,……都会匹配成功,
但加上exact,只有当地址是/时被匹配,其他都不会匹配成功
6、event
类型: string | Array
默认值: 'click'
声明可以用来触发导航的事件。可以是一个字符串。
<router-link to="/document" event="mouseover">document</router-link>
如果我们不加event,那么默认情况下是当我们点击document的时候,跳转到相应的页面,但当我们加上event的时候,就可以改变触发导航的事件,比如鼠标移入事件
7、replace
类型: boolean
默认值: false
设置 replace 属性的话,当点击时,会调用 router.replace() 而不是 router.push(),于是导航后不会留下 history 记录。
8、append
类型: boolean
默认值: false
设置 append 属性后,则在当前 (相对) 路径前添加基路径
【相关推荐:vuejs视频教程】
The above is the detailed content of What is vue's navigation link component?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

You can add a function to the Vue button by binding the button in the HTML template to a method. Define the method and write function logic in the Vue instance.

The watch option in Vue.js allows developers to listen for changes in specific data. When the data changes, watch triggers a callback function to perform update views or other tasks. Its configuration options include immediate, which specifies whether to execute a callback immediately, and deep, which specifies whether to recursively listen to changes to objects or arrays.

Vue.js has four methods to return to the previous page: $router.go(-1)$router.back() uses <router-link to="/" component window.history.back(), and the method selection depends on the scene.

Vue multi-page development is a way to build applications using the Vue.js framework, where the application is divided into separate pages: Code Maintenance: Splitting the application into multiple pages can make the code easier to manage and maintain. Modularity: Each page can be used as a separate module for easy reuse and replacement. Simple routing: Navigation between pages can be managed through simple routing configuration. SEO Optimization: Each page has its own URL, which helps SEO.

Netflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema

There are three ways to refer to JS files in Vue.js: directly specify the path using the <script> tag;; dynamic import using the mounted() lifecycle hook; and importing through the Vuex state management library.

There are three common methods for Vue.js to traverse arrays and objects: the v-for directive is used to traverse each element and render templates; the v-bind directive can be used with v-for to dynamically set attribute values for each element; and the .map method can convert array elements into new arrays.
