使用AngularJS排除url中的路径 [英] Excluding path in url using AngularJS

查看:29
本文介绍了使用AngularJS排除url中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 angular 应用程序有多个用户可以访问的页面,我想隐藏所有其他 url,只向用户显示基本 url.所以想象我的基本网址是:www.example.com,我还有其他页面,如关于、联系我们等.目前,当用户点击关于时,网址会更改为 www.example.com/about.angular 是否可以不添加/about"?这可以使用angular js吗?另外,我一直在寻找解决方案并尝试使用ui-router.js,这个模块也可以吗?

My angular application has multiple pages which users can visit and I would like to hide all other urls and only show users the base url. So imagine my base url is: www.example.com and I have other pages like About, Contact Us etc. Currently, when the user clicks on About, the url changes to www.example.com/about. Is it possible for angular not to add the "/about"? Is this possible using angular js? Also, I have been searching for solutions and have experimented with ui-router.js, is it also possible with this module?

推荐答案

如果你使用的是 ui-router,那么你可以像

If you are using ui-router, then you can define states without specifying urls like

myApp.config(function($stateProvider, $urlRouterProvider) {
    //
    // For any unmatched url, redirect to /state1
    $urlRouterProvider.otherwise("/state1");
    //
    // Now set up the states
    $stateProvider
        .state('state1', {
            url: "/state1",
            templateUrl: "state1.html",
            controller: 'Controller3'
        })
        .state('state2', {
            templateUrl: "state2.html",
            controller: 'Controller2'
        })
        .state('state3', {
            templateUrl: "state3.html",
            controller: 'Controller3'
        })
});

所以默认情况下 url 将是/state1.您可以通过在模板中使用 ui-sref 指令来实现导航,例如 ui-sref="state2" 或在控制器中使用 $state 服务,例如 $state.go('state2').

So by default the url will be /state1. And you can implement navigation by using ui-sref directive in your template like ui-sref="state2" or using $state service in your controller like $state.go('state2').

这篇关于使用AngularJS排除url中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆