如何在 Nuxt.js 中获取当前路由名称? [英] How to get current route name in Nuxt.js?

查看:495
本文介绍了如何在 Nuxt.js 中获取当前路由名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nuxt.js 来构建静态网站.

如何在组件的 script 代码中访问当前显示的路由名称(我想避免从浏览器位置读取直接 url)?

我可以以某种方式访问​​ $route.name 吗?

解决方案

是的,您可以使用 vuejs 路由对象,例如 $route.name$route.path

$nuxt.$route.path

返回当前路径

$nuxt.$route.name

当前路线的名称,如果有的话.

你这样做:

 数据(){返回 {区域:this.$nuxt.$route.query.zone,jour: this.$nuxt.$route.query.jour} },

**

I'm using Nuxt.js for building a static website.

How to access in component's script code currently displayed route name (I would like to avoid reading direct url from browser location)?

Can I somehow access $route.name ?

解决方案

yes you can use vuejs route objects like $route.name or $route.path

$nuxt.$route.path

return current path

$nuxt.$route.name

The name of the current route, if it has one.

Route Object Properties

A route object represents the state of the current active route. It contains parsed information of the current URL and the route records matched by the URL.

  • $route.path

    • type: string

    • A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar".

  • $route.fullPath

    • type: string

    • The full resolved URL including query and hash.

**

And if you want to get the url params. Like this : You do this:

  data() {
    return {
       zone: this.$nuxt.$route.query.zone,
       jour: this.$nuxt.$route.query.jour

    }   },

**

这篇关于如何在 Nuxt.js 中获取当前路由名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆