ktquez / vue-head

Manager the meta information of the head tag, a simple and easy way
MIT License
984 stars 73 forks source link

Meta tags not reset on navigate #96

Closed bronthulke closed 1 year ago

bronthulke commented 4 years ago

I'm hoping to use this plugin to set specific meta data (title, keywords, og: tags etc) on certain pages, but I want it to fallback to the defaults when you navigate to any page that does NOT specify tag data.

The problem is, it doesn't appear to reset the tags if a user moves to a page that has no overrides.

For example, in my main file I have this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Test App</title>

    <meta name="keywords" content="standard keywords, more keywords" id="keywords" />
    .... etc ....

I have a view "tagged-view" that has this within it:

head: {
    title: { inner: 'My Special Page' },
        meta: [
            { name: 'keywords', content: 'special keywords, different words', id: 'keywords' }
        ]
    },

Note that I'm using the id attribute to do replacement of the tag, and that's working.

If I go to "/" I see the default title ("My Test App") and default keywords ("standard keywords, more keywords").

Then if I click a router link to go to /tagged-view, I can see the title is now "My Special Page | My Test App", and the keywords have changed to "special keywords, different words".

However, if I then click a router link to go back to "/" I see that title has changed back to the default ("My Test App") but the keywords are still showing the customised version ("special keywords, different words'"). It only resets back to the defaults if I do a full page refresh.

So it seems as though the only way to have a deafult is to actually physically set the keywords etc (for ALL my meta tags) on every single page.

Is this a known/intended behaviour, or is there some config I can set to ensure it resets on every navigation?

Thanks :)

ktquez commented 4 years ago

Hello @bronthulke

Thanks for your feedback.

Could you reproduce this example online?

bronthulke commented 4 years ago

Hey @ktquez, sorry for the delay but I have it up on a live site now where you can see it.

If you go to http://54.206.8.208:8089/ the default keywords (which are set in my index.html) are shown - that's the keywords ending in "tennis tournament app". For that home view (home.vue) I do have a set of meta in the vue file and the words are the SAME in there as in the index.html default file.

If you then navigate using the menus to get to Features > League Management, you will see that the keywords meta is updated to be a set ending with "tennis courts near me".

Then if you navigate to Contact Us, you'll see that the keywords stay the same (ending in "tennis courts near me") rather than resetting to the defaults that end in "tennis tournament app".

You'll also see that it's not picking up my default title and appending it to the end, instead it's appending "Vue App". I do have a default title set ("Str8 Sets Tennis | For Clubs, Players, Competitions") and that was working in my dev build but isn't working as expected in this production build.

I hope this is clear, it's hard to describe it succinctly :)

Thanks!

bronthulke commented 4 years ago

Just an update on this, the title thing turned out to be our issue (something was going wrong in the build), so it's only the default meta fallback issue that I still have :)

ktquez commented 4 years ago

Hey @bronthulke, sorry for the delay. I managed to see the error.

I will do some tests, and soon as done I give you feedback here with the solution or a new fixed version.

ktquez commented 3 years ago

@bronthulke I missed this issue, did you manage to solve it??

bronthulke commented 3 years ago

Hey @ktquez, it's still an issue and unfortunately I haven't even had a chance to dig in any deeper myself.

Aryan3212 commented 1 year ago

Having the same issue here, is anyone actively maintaining this? If yes, I'll try to fix this.

Aryan3212 commented 1 year ago

@ktquez I fixed this on my side, any tags that have been substituted will get reset on navigate. Open to discuss, whether this could be an intended feature.

ktquez commented 1 year ago

Hi @Aryan3212, how are you? It would be an honor to receive your PR

Aryan3212 commented 1 year ago

Hey @ktquez I'm good. How are you? Just opened #104, do have a look, would love to get feedback.

On a side note, I'm having some trouble writing the test suites, I'm trying to render an App with some existing meta tags, with two children that have their own head property. How do I go about doing this?