visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 688 forks source link

How to set context#title? #463

Open elihorne opened 6 years ago

elihorne commented 6 years ago

First, thank you for creating this excellent router.

I notice in the documentation that you mention accessing the pushState page title via context, but I can't find any example of how this can be set by the routing functions.

Would it be possible to add an example of setting context values in the documentation?

antoc0d3 commented 6 years ago

Hi. you can extract the title from the content loaded by ajax. simply use this function.

function extractTitle(content) { return content.match(/<title[^>]*>([^<]+)<\/title>/)[1]; };

$("title").text(extractTitle(content));