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
随机推荐
- P5644-[PKUWC2018]猎人杀【NTT,分治】
正题 题目链接:https://www.luogu.com.cn/problem/P5644 题目大意 \(n\)个人,每个人被选中的权重是\(a_i\).每次按照权重选择一个没有死掉的人杀死,求第\ ...
- Windows 10、Windows Server 定时任务(定时关机)
前言 在测试过程中,有些测试机每天都需要关机,一台台很麻烦,于是想起了Windows的任务计划程序,想着试一试,就将具体过程记录一下. 过程 Windows 搜索任务计划程序 创建任务(不要选错了) ...
- Sentry 监控 - Distributed Tracing 分布式跟踪
系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...
- HCNP Routing&Switching之BGP基础
前文我们了解了路由注入带来的问题以及解决方案相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15362604.html:今天我们来学习下新的路由协议BG ...
- Python简单爬取图书信息及入库
课堂上老师布置了一个作业,如下图所示: 就是简单写一个借书系统. 大概想了一下流程,登录-->验证登录信息-->登录成功跳转借书界面-->可查看自己的借阅书籍以及数量... 登录可以 ...
- 洛谷1501 Tree II(LCT,路径修改,路经询问)
这个题是一个经典的维护路径信息的题,对于路径上的修改,我们只需要把对应的链\(split\)上来,然后修改最上面的点就好,注意pushdown的时候的顺序是先乘后加 然后下传乘法标记的时候,记得把对应 ...
- C#开发BIMFACE系列53 WinForm程序中使用CefSharp加载模型图纸1 简单应用
BIMFACE二次开发系列目录 [已更新最新开发文章,点击查看详细] 在我的博客<C#开发BIMFACE系列52 CS客户端集成BIMFACE应用的技术方案>中介绍了多种集成BIM ...
- Install WSL
Install WSL Prerequisites You must be running Windows 10 version 2004 and higher (Build 19041 and hi ...
- Promise.resolve(x)中x有几种情况
ps:下面参数说的是Promise.resolve(x)中的x 一共四种情况: 1.如果参数是Promise实例本身,则抛出错误 2.如果参数是一个promise对象,则then函数的执行取决于这个参 ...
- vue如何监听数组的变化
export function def (obj: Object, key: string, val: any, enumerable?: boolean) { Object.defineProper ...