路由更改时更改元标记
Change meta tag when route change
我正在使用 jq-router 开发一个简单的导航栏。我的目标是使用此插件制作单页应用程序。
我的问题是如何在更改 url.
时更改标题等元标记
希望你能帮助我。
谢谢。
(function () {
var routes = {},
defaultRoute = 'home';
routes['home'] = {
url: '#/',
templateUrl: 'pages/home.php',
title: 'This is the Homepage'
};
routes['about'] = {
url: '#/about',
templateUrl: 'pages/about.php',
title: 'This is the About page'
};
routes['contact'] = {
url: '#/contact',
templateUrl: 'pages/contact.php',
title: 'This is the Contact page'
};
$.router
.setData(routes)
.setDefault(defaultRoute);
$.when($.ready)
.then(function() {
$.router.run('.my-view','home');
});
}());
您必须使用 onViewChange
(here) 回调:
$.router.onViewChange( function(e, viewRoute, route, params){
document.title = route.title;
});
我正在使用 jq-router 开发一个简单的导航栏。我的目标是使用此插件制作单页应用程序。 我的问题是如何在更改 url.
时更改标题等元标记希望你能帮助我。
谢谢。
(function () {
var routes = {},
defaultRoute = 'home';
routes['home'] = {
url: '#/',
templateUrl: 'pages/home.php',
title: 'This is the Homepage'
};
routes['about'] = {
url: '#/about',
templateUrl: 'pages/about.php',
title: 'This is the About page'
};
routes['contact'] = {
url: '#/contact',
templateUrl: 'pages/contact.php',
title: 'This is the Contact page'
};
$.router
.setData(routes)
.setDefault(defaultRoute);
$.when($.ready)
.then(function() {
$.router.run('.my-view','home');
});
}());
您必须使用 onViewChange
(here) 回调:
$.router.onViewChange( function(e, viewRoute, route, params){
document.title = route.title;
});