gpt4 book ai didi

javascript - 我们可以在angular js中的$routeProvider.when()函数中传递两个参数吗

转载 作者:行者123 更新时间:2023-11-30 08:27:57 24 4
gpt4 key购买 nike

我正在尝试为两条路径重定向 home.html

例如我有一个这样的 anchor 标签 <a href="/home">Home</a>它可能是 <a href="/index">Home</a> ,在这两种情况下,我都希望它重定向到单个 URL (home.html)

我尝试过的

app.config(function($routeProvider){
$routeProvider
.when("/home", "/index", {
templateUrl : "home.html"
})
.otherwise({
redirectTo : "home"
});
});

但是我上面的代码不起作用。还有其他可能的解决方案吗?如果是这样,请提出建议,在此先感谢。

最佳答案

试试这个:

app.config(function($routeProvider){
$routeProvider
.when("/home", {
templateUrl : "home.html"
})
.when("/index", {
templateUrl : "home.html"
})
.otherwise({
redirectTo : "home"
});
});

关于javascript - 我们可以在angular js中的$routeProvider.when()函数中传递两个参数吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42199650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com