Dynamic Route Matching

动态的 路由 匹配

Very often we will need to map routes with the given pattern to the same component. For example we may have a User component which should be rendered for all users but with different user IDs. In vue-router we can use a dynamic segment in the path to achieve that:

需要通过给定的模式去导航路由到相同的模块,比如我们有一个用户组件,它被每个用户所使用,但是每个用户有不同的id。在vue 路由中,我们可以使用一个动态的部分 来实现它。

const User = {
template: '<div>User</div>'
} const router = new VueRouter({
routes: [
// dynamic segments start with a colon
{ path: '/user/:id', component: User }
]
})

  

Now URLs like /user/foo and /user/bar will both map to the same route.

现在 像/user/foo 和 /user/bar 的URLS 将被同时导航到 相同的 地方

A dynamic segment is denoted by a colon :. When a route is matched, the value of the dynamic segments will be exposed as this.$route.params in every component. Therefore, we can render the current user ID by updating User's template to this:

一个动态的部分被: 标志, 当一个路由相匹配时,动态变量的值将会被暴露为this.$route.params,在每一个组件里。因此,我们可以填充当前的用户id通过更新用户组件成这样:

const User = {
template: '<div>User {{ $route.params.id }}</div>'
}

You can have multiple dynamic segments in the same route, and they will map to corresponding fields on $route.params. Examples:

你可以有很多多样的的动态变量在同一个路由里面,他们将映射到对应的部分,在$route.params

pattern matched path $route.params
/user/:username /user/evan { username: 'evan' }
/user/:username/post/:post_id /user/evan/post/123 { username: 'evan', post_id: '123' }

In addition to $route.params, the $route object also exposes other useful information such as $route.query (if there is a query in the URL), $route.hash.etc. You can check out the full details in the API Reference

除了 $route.params, $route 对象还暴露出其他的有用信息,比如 路由?,路由的哈希,等等。你可以查询所有的细节在api参考里。

Dynamic Route Matching Vue路由(1)的更多相关文章

  1. Vue路由vue-router

    前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL,实现URL和组件的对应,以及通过U ...

  2. Vue 路由详解

    Vue 路由详解 对于前端来说,其实浏览器配合超级连接就很好的实现了路由功能.但是对于单页面应用来说,浏览器和超级连接的跳转方式已经不能适用,所以各大框架纷纷给出了单页面应用的解决路由跳转的方案. V ...

  3. Vue路由-详细总结

    Vue路由vue-router   前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL ...

  4. Vue路由Hash模式分析

    Vue路由Hash模式分析 Vue-router是Vue的核心组件,主要是作为Vue的路由管理器,Vue-router默认hash模式,即使用URL的Hash来模拟一个完整的URL,当URL改变时页面 ...

  5. Vue路由History模式分析

    Vue路由History模式分析 Vue-router是Vue的核心组件,主要是作为Vue的路由管理器,Vue-router默认hash模式,通过引入Vue-router对象模块时配置mode属性可以 ...

  6. Vue路由学习心得

    GoodBoy and GoodGirl~进来了就看完点个赞再离开,写了这么多也不容易的~ 一.介绍  1.概念:路由其实就是指向的意思,当我们点击home按钮时,页面中就要显示home的内容,点击l ...

  7. vue路由原理剖析

    单页面应用(SPA)的核心之一是: 更新视图而不重新请求页面, 实现这一点主要是两种方式: 1.Hash: 通过改变hash值 2.History: 利用history对象新特性(详情可出门左拐见:  ...

  8. vue路由vue-router的使用

    对于单页应用,官方提供了vue-router进行路由跳转的处理. 安装 基于传统,我更喜欢采用npm包的形式进行安装. npm install vue-router --save 当然,官方采用了多种 ...

  9. 3种vue路由传参的基本模式

    路由是连接各个页面的桥梁,而参数在其中扮演者异常重要的角色,在一定意义上,决定着两座桥梁是否能够连接成功. 在vue路由中,支持3中传参方式. 场景,点击父组件的li元素跳转到子组件中,并携带参数,便 ...

随机推荐

  1. 【剑指Offer面试编程题】题目1391:顺时针打印矩阵--九度OJ

    题目描述: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2 ...

  2. 如何反编译MIPS64伪代码?用Ghidra

    在分析固件时,碰到MIPS64架构的程序会很头疼,虽然用IDA能够反编译出汇编代码,但是没办法F5一键反编译成伪代码,如果单看汇编,看久了脑壳痛. 后来Google到了一个好工具,Ghidra,发音和 ...

  3. cover-view子节点溢出父节点被剪切的问题

    因为之前在使用自定义tabbar的时候,使用了cover-view, 导致溢出父节点的那部分被剪切掉,因为没找到有类似的问题出现, 所以我在布局方面做了调整: .tab-bar { overflowY ...

  4. JS控制输入框和文本框字数

    文本框限制字数: HTML结构: JS: $('.advert-title').each(function(){ var TXTlength = $(this).text().length; // 当 ...

  5. php 等于不等于 一个感叹号两个等于号

    $a == $b 等于 TRUE,如果 $a 等于 $b. $a === $b 全等 TRUE,如果 $a 等于 $b,并且它们的类型也相同.(PHP 4 引进) $a != $b 不等 TRUE,如 ...

  6. 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:匿名内部类

    interface A{ public void printInfo() ; // } class B implements A{ // 实现接口 public void printInfo(){ S ...

  7. UITree_study

    1.Create canvas 2.Add TreeView 3.Subscribe and unsubscribe events(订阅和取消订阅事件) 4.Data bind items it's ...

  8. CC3200 飞行计划

    CC3200 飞行计划 2016-01-25 CC3200 资源 CC3200_JTAG调试 CC3200-Uniflash 烧写程序 Mosquitto搭建MQTT 服务器 [示例] CC3200_ ...

  9. Day6-T1

    原题目 Describe:模拟大水题 code: #include<bits/stdc++.h> #define INF 214748364 #define eps 1e-9 #defin ...

  10. springboot官网->application.properties文件

    springboot application.properties 2.1.6.RELEASE