vue .js动态页面标题

发布于 2025-02-09 19:09:12 字数 749 浏览 1 评论 0原文

尝试根据VUEJS项目中的URL参数更改页面标题。

路由器中具有缠绕路径:

 {
   path: '/:location',
   name: 'home_spec',
   components: { default: Home, header: StarterNavbar, footer: StarterFooter },
 }

并将位置推入路由器中的标题:

router.beforeEach((to, from, next) => {
  if (to.params.location){
    document.title = `${to.params.location}`
  }else{
    document.title = "Default title"
  }
  next()
})

in index.html具有

 <title><%= htmlWebpackPlugin.options.title %></title>

,并且效果很好(TAB具有可见的可见title) surececode(ctrl+u)具有默认标题,如包JS名称参数所示。

是否可以在水疗中心发送带有理想标题的第一个HTML页面? 如果答案是否定的,那么SEO对于搜索机器人至关重要?

Trying to change page title depending on URL params in VueJS project.

In router have the folowing path:

 {
   path: '/:location',
   name: 'home_spec',
   components: { default: Home, header: StarterNavbar, footer: StarterFooter },
 }

and pushing location to title also in router:

router.beforeEach((to, from, next) => {
  if (to.params.location){
    document.title = `${to.params.location}`
  }else{
    document.title = "Default title"
  }
  next()
})

in index.html have

 <title><%= htmlWebpackPlugin.options.title %></title>

And it works fine (tab has desireable title ) BUT sourcecode (CTRL+U) has the default title as in the package,js name parameter.

Is it possible to send the first html page with the desirable title in SPA?
If the answer is no, what about SEO is it critical for searching robots?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜中书 2025-02-16 19:09:12

也许尝试另一种设置页面标题的方式?例如,您可以做:

  {
   path: '/:location',
   name: 'home_spec',
   components: { default: Home, header: StarterNavbar, 
                 footer:StarterFooter },
   meta: { pageTitle: 'example' }

  router.beforeEach((to, from) => {
   document.title = to.meta.title;
   } )

Maybe try another way of setting page title? for example u can do:

  {
   path: '/:location',
   name: 'home_spec',
   components: { default: Home, header: StarterNavbar, 
                 footer:StarterFooter },
   meta: { pageTitle: 'example' }

  router.beforeEach((to, from) => {
   document.title = to.meta.title;
   } )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文