Part 28 AngularJS default route
At the moment the problem is that, if you try to navigate to a route that is not configured, you will see only the layout page without any partial template injected into it.
For example if you navigate to http://localhost:51983/ABC, since ABC is not a configured route you will see the layout page (index.html) as shown below.
You will also have this same problem if you navigate to the root of the site i.ehttp://localhost:51983. The reason angular is displaying the empty layout template in both these cases, is because it does not know what partial template to inject. We want angular to redirect to default route if the user is trying to navigate to a route that is not configured.
How to configure the default route in Angular : Well that is straight forward. All you need is the following line in config() function in script.js file
.otherwise({
redirectTo: "/home"
})
With the above change the code in config() function should be as shown below.
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when("/home", {
templateUrl: "Templates/home.html",
controller: "homeController"
})
.when("/courses", {
templateUrl: "Templates/courses.html",
controller: "coursesController"
})
.when("/students", {
templateUrl: "Templates/students.html",
controller: "studentsController"
})
.otherwise({
redirectTo: "/home"
})
$locationProvider.html5Mode(true);
})
With this change if the user tries to navigate to a route that is not configured (http://localhost:51983/ABC) or just to the rooot URL (http://localhost:51983), the user will be automatically redirected to http://localhost:51983/home.
Part 28 AngularJS default route的更多相关文章
- Default route and zero route
A default route of a computer that is participating in computer networking is the packet forwarding ...
- FreeBSD Set a Default Route / Gateway
Task: View / Display FreeBSD Routing Table Use netstat command with -r option:$ netstat -r$ netstat ...
- 永久改动redhat的default route
1,能够用route命令暂时改动: route add default gw <gateway ip> 2, 通过改动/etc/sysconfig/network 文件永久改动: 脚本: ...
- 【angularJS】Route路由
介绍 AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA). ...
- angularJS中-$route路由-$http(ajax)的使用
后台请求使用的是nodeJS驱动(后面帖代码),很简单的RESTFUL, 页面使用的是bottstarp3.0(懒人神器); 第一个例子: 在本地架设NODEJS, angular的所有请求都是请求本 ...
- [AngularJS] Default Child state and nav between child state
Let's say we want a parent state which is a abstract state. Two children states, one is for sinlge a ...
- AngularJS中Route例子
代码:https://files.cnblogs.com/files/xiandedanteng/angularJSRouteSample.rar 点击‘首页’后: 点击‘电脑’后: <!DOC ...
- 002 static and default route
r2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1 r1(config)#ip route 192.168.3.0 255.255.25 ...
- Change Default Route
route delete 0.0.0.0route add 0.0.0.0 mask 0.0.0.0 10.226.4.14
随机推荐
- Python日常Bug集
1.TypeError: 'int' object is not iterable: 场景示例: data = 7 for i in data: print(i) # 原因:直接对int数据进行迭代造 ...
- pymysql链接时,密码含有特殊符号。
类如含有@之类的特殊符号,在链接数据库时,需要提前url转码,不然会报密码错误. python3/2分别引用是同样的第三方库,但是引用方式不同 python2 from urllib import q ...
- 在Windows Server 2012R2离线安装.net framework3.5
最近新装了一台Windows Server 2012 R2的服务器,安装数据库时,出现了提示安装不上 .net framework3.5的情况,经过网络上多次的资料查找及反复试验终于找到了一个可以解决 ...
- Sentry 监控 - Snuba 数据中台架构(Query Processing 简介)
系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...
- 详解package-lock.json的作用
目录 详解package-lock.json package-lock.json的作用 版本号的定义规则与前缀对安装的影响 改动package.json后依旧能改变项目依赖的版本 当前项目的真实版本号 ...
- 面试官:为什么需要Java内存模型?
面试官:今天想跟你聊聊Java内存模型,这块你了解过吗? 候选者:嗯,我简单说下我的理解吧.那我就从为什么要有Java内存模型开始讲起吧 面试官:开始你的表演吧. 候选者:那我先说下背景吧 候选者:1 ...
- Vue3学习(五)之集成HTTP库axios
一.安装axios npm install axios@0.21.0 --save 二.axios的使用 1.在主页中引用axios 在Vue3新增了setup初始化方法,所以我们在这里开始使用并测试 ...
- jsonp和cors解决跨域
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.对于JSON大家应该是很了解了吧,不是很清楚的朋友可以去json.org上了解下,简单易懂. 1.什么是跨 ...
- Linux命令查看内存、整体负载、端口查看、进程查看、vim编辑器(3)
一.资源占用命令 1.查看内存(free) free命令默认是以kb为单位显示的. free -m用Mb单位来显示. free -h显示单位 . free -h -s 3 ,每隔三秒刷新一次,如果 ...
- 【数据结构与算法Python版学习笔记】树——二叉树的应用:解析树
解析树(语法树) 将树用于表示语言中句子, 可以分析句子的各种语法成分, 对句子的各种成分进行处理 语法分析树 程序设计语言的编译 词法.语法检查 从语法树生成目标代码 自然语言处理 机器翻译 语义理 ...