-
Notifications
You must be signed in to change notification settings - Fork 25.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(router): Add Route.metatags
and Route.pageDescription
to Route definitions
#44928
Comments
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list. You can find more details about the feature request process in our documentation. |
I think there is a lot missing in this proposal. There is already the Meta Service https://angular.io/api/platform-browser/Meta to allow setting metatags. And I doubt the static tags and descriptions will be useful for most use cases. I also have the feeling that routes get cluttered with a lot of stuff. When seeing this I'm not sure if it's a good idea to have title so prominent in the routes and seperated from all other SEO meta stuff. Probably it would be better to have a titleMetaDescription resolver that handles everything together, because it can be expected that they will have some stuff in common. |
I agree this feature would reduce COMMON efforts of developers, but my concern is the responsibility of routes. A route is not corresponding to the specific "page". There are more variable usecases of Router, for example multiple router-outlets. Or, we just want to a customizable generic (no rxjs) callback place to update page information where we can manage title, meta and etc on the successful route change. |
This comment was marked as abuse.
This comment was marked as abuse.
I think having a declarative way of setting the meta tags would go a long way of making the SEO story in Angular more compelling. Now that we can already set the title this way, having an option to do the same for tags seems like the logical next step.
For simple pages like home page or about page you could set it statically:
For more dynamic pages like product pages, you would provide a custom resolver:
While I understand that there is a risk of routes config getting cluttered with too many properties, from my point of view, setting both title and meta tags, seems very much related to routing. Most of the time you set both title and meta tags when you navigate to a page, and you update them when you navigate to the a different one.
That is a very valid concern, but I believe that solving a common pain point for many developers is something that we should strive for. Also, there seems to be a rather large group of people on social media saying that "Angular is only for admin panels and internal apps". I don't agree with that, and I think that shipping some new features that improve the DX for public/search discovered apps, could help shift that perception. |
Still I think that instead of adding this as separate properties you think something like {meta: MetaResolver} would be a lot more convenient. If you have to write a resolver for every property that probably all have a lot in common is very ugly. |
I love this idea. I was taking a look at best SEO practices and saw the new title feature for routes, which I guess was also added for improved SEO and/or a11y. I think meta tags make a lot of sense, thanks @twerske, I hope the proposal makes it into Angular in the future! |
I can do this one if there is agreement on the approach
and internally to call updateTag when the route changes question: should we add |
That looks a lot better as it will also allow to set any meta tags instead of a small defined set. This will make it a lot easier to provide the meta data used for share previous in facebook, twitter and similar services. |
…gular#44928) This commit provides a service, `PageTagsStrategy` for setting the document tags after a successful router navigation. Users can provide custom strategies by extending `TagsStrategy` and adding a provider which overrides it. The strategy takes advantage of the pre-existing `data` and `resolve` concepts in the Router implementation: We can copy the `Route.tags` into `data`/`resolve` in a non-breaking way by using a `symbol` as the key. This ensures that we do not have any collisions with pre-existing property names. By using `data` and `resolve`, we do not have to add anything more to the router navigation pipeline to support this feature. Closes angular#44928
This commit provides a service, `PageTagsStrategy` for setting the document tags after a successful router navigation. Users can provide custom strategies by extending `TagsStrategy` and adding a provider which overrides it. The strategy takes advantage of the pre-existing `data` and `resolve` concepts in the Router implementation: We can copy the `Route.tags` into `data`/`resolve` in a non-breaking way by using a `symbol` as the key. This ensures that we do not have any collisions with pre-existing property names. By using `data` and `resolve`, we do not have to add anything more to the router navigation pipeline to support this feature. Closes angular#44928
This commit provides a service, `PageTagsStrategy` for setting the document tags after a successful router navigation. Users can provide custom strategies by extending `TagsStrategy` and adding a provider which overrides it. The strategy takes advantage of the pre-existing `data` and `resolve` concepts in the Router implementation: We can copy the `Route.tags` into `data`/`resolve` in a non-breaking way by using a `symbol` as the key. This ensures that we do not have any collisions with pre-existing property names. By using `data` and `resolve`, we do not have to add anything more to the router navigation pipeline to support this feature. Closes angular#44928
Which @angular/* package(s) are relevant/releated to the feature request?
@angular/router
Description
As a follow up to #7630 it would be nice to also add both
metatags
andpageDescription
to the router's definition API in order to streamline how developers define routes.We can also explore what other data is commonly defined and managed with custom strategies in the
Route.data
property to see how else we could simplify Route definitions especially for new developers.Proposed solution
Alternatives considered
Currently this is individually managed and already possible with the
Route.data
additional attributes, which works but is more work for the developer and does not enforce best practices.The text was updated successfully, but these errors were encountered: