question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refreshing page doesn't set the title or description that's defined in the router

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => check the README and search github for a similar issue or PR before submitting
[ ] support request => check the README and search github for a similar issue or PR before submitting
[ ] feature request

Current behavior If I go from page 1 to page 2, the metas are set correctly, but if I go from page 1 to page 2 and then refresh on page 2, page 2’s metas aren’t being set.

Expected/desired behavior I expect the page 2’s metas to be set on refresh as well.

Minimal reproduction of the problem with instructions See current behavior.

  • Angular version: 2.0.X 2.3.1

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] all

  • Language: [all | TypeScript X.X | ES6/7 | ES5] all

  • Node (for AoT issues): node --version =
    6.7

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fulls1z3commented, Apr 1, 2017

Hi @bjornharvold, now with this repro steps I can have a better understanding about the issue, thank you for the provided information 👍

A similar topic was just discussed on #30: without defer argument set to false, setTitle/setTag methods simply subscribe to the NavigationEnd event of the router. However, the observable above gets resolved after that event.

There’s a subscription bound to the event, true. But it cannot be triggered just because NavigationEnd event was emitted earlier. In this case, passing false to defer would execute the method immediately.

I’m thinking about possibilities without listening to NavigationEnd event, however options are quite limited as NavigationEnd is the only event whom we can retrieve urlAfterRedirects property. We can’t expect further functionality from the Angular team quite soon, as they’re quite busy with the i18n stuff nowadays. However, if I can find an opportunity (there’re possibilities, yes) to make it work with the desired way, be sure I’ll get it done.

On the other hand, this issue reveals the fact that I need to document the behavior of defer argument at the README - we can’t expect people what’s under hood at the first glance 😃

So, I want to say my thanks again to @chrillewoodz @cybey and @bjornharvold for all your contributions.

0reactions
bjornharvoldcommented, Apr 1, 2017

Than you for the mention @fulls1z3 😉 The problem I was having was not setting it directly but like this:

My current code:

this.activatedRoute.params
      .map(params => params['id'])
      .flatMap(id => this.hotelService.retrieveMetaData(id))
      .subscribe((list: Array<MetaData>) => {
          if (list && list.length > 0) {
            list.forEach(md => {
              switch (MetaDataType[md.type]) {
                case MetaDataType.PAGE_TITLE:
                  this.metaService.setTitle(md.value, false, false);
                  break;
                case MetaDataType.METADATA:
                  this.metaService.setTag(md.key, md.value, false);
                  break;
                default:
                  console.log('do not know how to handle metadata type: ' + md.type);
              }
            });
          }
        },
        error => {
          return Observable.of<Array<MetaData>>();
        },
        () => {
        }
      );

Unless I add “false, false” the title doesn’t update

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular2 rc1 default route issue when refresh page
UPDATE TO RC5​​ Show activity on this post. One way to define a default routes with the new RC router is @Routes([ {...
Read more >
Angular 14 Router - Updating the Page Title (2022) - YouTube
Every Angular Route has a dedicated property called " title " where you can define a title or the resolver that can perform...
Read more >
Setting Page Titles Natively With The Angular Router
This post shows you how to use the Angular Router's new built-in feature to for setting the page title after each successful navigation....
Read more >
Dynamic Page Titles in Angular
In this post, we will go through how we can set the browser (page/document) title for the entire app and we can programmatically...
Read more >
ASP.NET Core Blazor routing and navigation
Learn how to manage request routing in Blazor apps and how to use the Navigation Manager and NavLink component for navigation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found