Javascript 如何在$routeProvider中捕获特定url
我要捕获的URL是 我需要在$routeProvider中捕获上述url。 我的密码是Javascript 如何在$routeProvider中捕获特定url,javascript,angularjs,Javascript,Angularjs,我要捕获的URL是 我需要在$routeProvider中捕获上述url。 我的密码是 $routeProvider.when('/:code/',{ template: '', controller: function ($location,$rootScope) { console.log("I got you. .. ");
$routeProvider.when('/:code/',{
template: '',
controller: function ($location,$rootScope) {
console.log("I got you. .. ");
}
})
.otherwise({
redirectTo: '/login'
});
我的问题是我无法在中捕获此url
感谢您的帮助。使用
$routeParam
$routeProvider.when('/:code/',{
template: '',
controller: function ($location,$rootScope) {
var urlCopied=$location.path(); // get the current path
}
})
.otherwise({
redirectTo: '/login'
});
希望对你有所帮助你可以试试这个
//给定的urlhttp://example.com/#/some/path?foo=bar&baz=xoxo
var absUrl=$location.absUrl();
// => "http://example.com/#/some/path?foo=bar&baz=xoxo“
从有两种方法可以满足您的需求:
$routeProvider.when('/code/codeID',{
template: '',
controller: function ($routeParams) {
console.log($routeParams.codeID);
}
})
.otherwise({
redirectTo: '/login'
});
$routeProvider.when('/code/codeID',{
template: '',
controller: function ($routeParams) {
console.log($routeParams.codeID);
}
})
.otherwise({
redirectTo: '/login'
});
$routeProvider.when('/',{
template: '',
controller: function ($location) {
var queryParams = $location.search();
console.log(queryParams.code);
}
})
.otherwise({
redirectTo: '/login'
});
http://test.sample.com/?code=4/CAKREYsOD89sg7eXahK93Pw7pnMb5ndkiCrzSUlMS1U
我希望这段代码能帮助你 我需要得到上面的网址被捕获。这与解析url无关。抱歉@Explore-X,编辑了答案检查是否有用。这与$routeProvider有关。当(“/:code/”时,此通配符上未捕获url。我认为这是因为“?”重试