使用参数为 Angular (ui.router) 配置路由
Configure Routing for the Angular (ui.router) with a Parameter
使用 AngularJs 和 UI-Router 为多租户前端应用程序设置路由。
例如,当用户键入以下内容时 URL 应该为 userxyz 加载仪表板并且 参数必须通过会话在用户的浏览器中维护,所以用户应该能够浏览应用程序中的其他超链接。
http://servername.com/#/dashboard/userxyz
正在努力实现这个,我看了一些教程但无法理解。
这是我的路由配置代码。
(function () {
'use strict';
app.config(["$stateProvider", "$urlRouterProvider",
function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state("dashboard", {
url: "/dashboard/{tenantid}",
templateUrl: "app/components/dashboard/dashboardView.html",
controller: "DashboardController"
})
.state("people", {
url: "/people/{tenantid}",
templateUrl: "app/components/people/peopleView.html",
controller: "PeopleController"
})
.state("contact", {
url: "/contact/{tenantid}",
templateUrl: "app/components/contact/contactView.html",
controller: "ContactController"
})
$urlRouterProvider.otherwise("/dashboard/{tenantid}");
}]);
})();
在我的 index.html 中,我有以下代码在 ui-view 中显示状态:
<div class="row" ui-view>
</div>
而且,我确实设法使用 ui-sref 设置了超链接,这里是这样的:
<a ui-sref="dashboard">Home</a>
<a ui-sref="people">People</a>
<a ui-sref="contact">Contact</a>
更好的用户本地 o 会话存储以保存租户
根据之前的评论:
如果您不需要对 ie7 的支持(希望如此),请尝试使用本机浏览器 localStorage
,用于插入项目 localStorage.setItem('key', 'value')
用于检索 localStorage.getItem('key')
在此处查看 localStorage
浏览器支持 Local Storage Browser Support
使用 AngularJs 和 UI-Router 为多租户前端应用程序设置路由。
例如,当用户键入以下内容时 URL 应该为 userxyz 加载仪表板并且 参数必须通过会话在用户的浏览器中维护,所以用户应该能够浏览应用程序中的其他超链接。
http://servername.com/#/dashboard/userxyz
正在努力实现这个,我看了一些教程但无法理解。
这是我的路由配置代码。
(function () {
'use strict';
app.config(["$stateProvider", "$urlRouterProvider",
function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state("dashboard", {
url: "/dashboard/{tenantid}",
templateUrl: "app/components/dashboard/dashboardView.html",
controller: "DashboardController"
})
.state("people", {
url: "/people/{tenantid}",
templateUrl: "app/components/people/peopleView.html",
controller: "PeopleController"
})
.state("contact", {
url: "/contact/{tenantid}",
templateUrl: "app/components/contact/contactView.html",
controller: "ContactController"
})
$urlRouterProvider.otherwise("/dashboard/{tenantid}");
}]);
})();
在我的 index.html 中,我有以下代码在 ui-view 中显示状态:
<div class="row" ui-view>
</div>
而且,我确实设法使用 ui-sref 设置了超链接,这里是这样的:
<a ui-sref="dashboard">Home</a>
<a ui-sref="people">People</a>
<a ui-sref="contact">Contact</a>
更好的用户本地 o 会话存储以保存租户
根据之前的评论:
如果您不需要对 ie7 的支持(希望如此),请尝试使用本机浏览器 localStorage
,用于插入项目 localStorage.setItem('key', 'value')
用于检索 localStorage.getItem('key')
在此处查看 localStorage
浏览器支持 Local Storage Browser Support