Skip to content
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

Set document title on route change #725

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

agubler
Copy link
Member

@agubler agubler commented Apr 9, 2020

Type: feature

The following has been addressed in the PR:

Description:

Adds support for setting the document.title on route change. This can be done either statically in the route configuration, a callback passed to the router to dynamically set the title or a combination of the two.

Statically:

routes.ts

export default [
    {
        id: 'foo',
        path: 'foo/{param}?{queryParam}'
        outlet: 'foo',
        title: 'Foo Title'
    }
];

Dynamically on Router initialisation using the setDocumentTitle callback (using the injector registration as an example, but the same can be passed when instantiating a new Router directly):

registerRouterInjector(routes, registry, {
    setDocumentTitle: ({ title, id, params, queryParams }) => {
        if (outlet === 'dynamic-title-outlet') {
            return `${id}-${params.id}-${queryParams.bar}`;
        }
        return title;
    }
});

Currently the options interface for the setDocumentTitle look like:

export interface DocumentTitleOptions {
	title?: string;
	id: string;
	params: Params;
	queryParams: Params;
}

Resolves #601

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 9, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 07bae60:

Sandbox Source
runtime-grass-kxg1s Configuration

@codecov
Copy link

codecov bot commented Apr 9, 2020

Codecov Report

Merging #725 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #725   +/-   ##
=======================================
  Coverage   97.78%   97.78%           
=======================================
  Files         121      121           
  Lines        7052     7058    +6     
  Branches     1603     1606    +3     
=======================================
+ Hits         6896     6902    +6     
  Misses        156      156           
Impacted Files Coverage Δ
src/routing/Router.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74e5e4e...07bae60. Read the comment docs.

@agubler agubler merged commit 544207d into dojo:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Router should be able to change the document.title
2 participants