navigate
一、router.navigate的使用
navigate是Router类的一个方法,主要用来跳转路由。
函数定义:
|
1
|
navigate(commands: any[], extras?: NavigationExtras) : Promise`<boolean>` |
|
1
2
3
4
5
6
7
8
9
|
interface NavigationExtras { relativeTo : ActivatedRoute queryParams : Params fragment : string preserveQueryParams : boolean preserveFragment : boolean skipLocationChange : boolean replaceUrl : boolean} |
1.this.router.navigate(['user', 1]);
以根路由为起点跳转
2.this.router.navigate(['user', 1],{relativeTo: route});
默认值为根路由,设置后相对当前路由跳转,route是ActivatedRoute的实例,使用需要导入ActivatedRoute
3.this.router.navigate(['user', 1],{ queryParams: { id: 1 } });
路由中传参数 /user/1?id=1
4.this.router.navigate(['view', 1], { preserveQueryParams: true });
默认值为false,设为true,保留之前路由中的查询参数/user?id=1 to /view?id=1
5.this.router.navigate(['user', 1],{ fragment: 'top' });
路由中锚点跳转 /user/1#top
6.this.router.navigate(['/view'], { preserveFragment: true });
默认值为false,设为true,保留之前路由中的锚点/user/1#top to /view#top
7.this.router.navigate(['/user',1], { skipLocationChange: true });
默认值为false,设为true路由跳转时浏览器中的url会保持不变,但是传入的参数依然有效
8.this.router.navigate(['/user',1], { replaceUrl: true });
未设置时默认为true,设置为false路由不会进行跳转
二、router.navigate刷新页面问题
造成这个问题一般是因为我们在<form>表单中使用<button>时忘记添加type属性,在表单中,如果忘记给按钮添加属性,会默认为submit
|
1
|
<button (click)="toDetail()">detail</button> |
|
1
2
3
|
toDetail() { this._router.navigate(['/detail']);} |
解决方法:
1.添加type
|
1
|
<button type="button" (click)="toDetail()">detail</button> |
2.click添加false
|
1
|
<button (click)="toDetail();false">detail</button> |
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者使用Angular.js能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
navigate的更多相关文章
- (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
(App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKi ...
- window.navigate 与 window.location.href 的使用区别介绍
window.navigate(sURL)方法是针对IE的,不适用于FF,在HTML DOM Window Object中,根本没有列出window.navigate方法. 要在javascript中 ...
- 在wp中,使用NavigationService.Navigate导航页面出现错误
我们在WP项目中采用页面导航时候,经常会使用以下代码 NavigationService.Navigate(new Uri("/Page1.xaml",UriKind.Relati ...
- angular 的navigate 各种使用情况
navigate是Router类的一个方法,主要用来跳转路由. 函数定义: navigate(commands: any[], extras?: NavigationExtras) : Promise ...
- Angular4中路由Router类的跳转navigate
最近一直在学习angular4,它确实比以前有了很大的变化和改进,好多地方也不是那么容易就能理解,好在官方的文档和例子是中文,对英文不太好的还是有很大帮助去学习. 官方地址:https://angul ...
- ReactNative踩坑日志——页面跳转之——Undefined is not an Object(evaluating this2.props.navigation.navigate)
页面跳转时,报 Undefined is not an Object(evaluating this2.props.navigation.navigate) 出错原因:在一个页面组件中调用了另一个组 ...
- 在webBrowser1.Navigate(url)中设置Cookie的注意点
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static exte ...
- react-navigation 3.x版本的push、navigate、goback、pop、dispatch等常用方法
一.方法简介 1. 应用中的每个页面组件都会自动提供 this.props.navigation this.props.navigation可以获取的一些方法: navigate - 转到另一个页面, ...
- driver.get()和driver.navigate().to()到底有什么不同?-----Selenium快速入门(四)
大家都知道,这两个方法都是跳转到指定的url地址,那么这两个方法有什么不同呢?遇到这种情况,第一反应就是查查官方的文档. 官方文档的说法是:Load a new web page in the cur ...
- angular2 Router类中的路由跳转navigate
navigate是Router类的一个方法,主要用来路由跳转. 函数定义 navigate(commands: any[], extras?: NavigationExtras) : Promise` ...
随机推荐
- Alpha冲刺(6/10)——追光的人
1.队友信息 队员学号 队员博客 221600219 小墨 https://www.cnblogs.com/hengyumo/ 221600240 真·大能猫 https://www.cnblogs. ...
- Implicit declaration of function 'CC_MD5' is invalid in C99
//导入这个就行了#import <CommonCrypto/CommonDigest.h> //没有导包的时候,提示如下: Implicit declaration of functio ...
- 用yum安装完mysql后没有mysqld的问题
在Centos中用命令 yum install mysql安装数据库,但装完后运行mysqld启动mysql的时候提示找不到,通过 find / | grep mysqld 也没找到mysqld的目录 ...
- 【系统自启动】使用windows自带工具管理开机启动项
1.windows+R,键入:msconfig 2.进入启动选项卡 3.将不用自启动的选项 取消勾选即可 点击应用,重启电脑即可
- SQLAlchemy中filter()和filter_by()的区别
1.filter引用列名时,使用“类名.属性名”的方式,比较使用两个等号“==” 2.filter_by引用列名时,使用“属性名”,比较使用一个等号“=” 3.在使用多条件匹配的时候,filter需要 ...
- BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版
令\[S_i=\sum_{k=1}^n k^i m^k\]我们有\[\begin{eqnarray*}(m-1)S_i & = & mS_i - S_i \\& = & ...
- 利用Nodejs & Cheerio & Request抓取Lofter美女图片
还是参考了这篇文章: http://cnodejs.org/topic/54bdaac4514ea9146862abee 另外有上面文章 nodejs抓取网易公开课的一些经验. 代码如下,注意其中用到 ...
- 视差映射 parrallax mapping
算个新的uv在heightmap https://learnopengl.com/Advanced-Lighting/Parallax-Mapping https://blog.csdn.net/so ...
- 【云计算】IBM开放云架构
IBM 的开放云架构 通过改变业务和社会运行的方式,云计算开启了丰富的创新途径.开发人员现在正将记录系统与参与性系统相结合,一种新的基于云的应用程序风格正在出现:交互系统.这些应用程序要可持续发展,云 ...
- Node.js m03122图片批量下载爬虫1.00
//====================================================== // m03122图片批量下载爬虫1.00 // 2017年11月18日 //==== ...