angular的@uirouter的lazyload功能,在使用onBefore hook时,如果不进行一定设置是监听不到lazyload的hook的。原来是因为lazy loade hook的优先级是0,要设置此hook需要在onBefore中设置priority: 1

在uirouter的github的一个issue中给出了解释:传送门

You should be able to implement this with these existing primitives:
* lazyLoad property on a state
* An onBefore Transition Hook when entering a lazyload state
* A Transition promise
javascript
const criteria = { entering: (state) => !!state.lazyLoad };
const options = { priority: 1 };
const hook = trans => {
console.log('Lazy load starting...');
const done = () => console.log('Lazy load complete!');
trans.promise.then(done, done)
};
uiRouter.transitionService.onBefore(criteria, hook, options);

Here’s an example: https://stackblitz.com/edit/ui-router-angular-ysa7jk?file=app%2Fapp.module.ts

Note: priority: 1 is necessary because the lazy load hook itself is a priority 0 onBefore hook.

分类: angularjs

11 条评论

make g · 2020年6月20日 下午12:04

Write more, thats all I have to say. Literally, it seems as though you
relied on the video to make your point. You clearly know what youre talking about,
why waste your intelligence on just posting videos to your site when you could
be giving us something informative to read?

with g · 2020年6月22日 上午12:50

I’m extremely impressed with your writing skills
as well as with the layout on your weblog. Is this a paid
theme or did you modify it yourself? Either way keep up the
excellent quality writing, it’s rare to see a nice blog like
this one today.

millenniumtechnology.in · 2020年6月26日 下午12:57

whoah this weblog is great i like reading your articles.
Keep up the good work! You recognize, lots of individuals are hunting around for this
information, you can help them greatly.

http://tinyurl.com · 2020年6月27日 上午12:55

Wow! At last I got a weblog from where I know how to truly take helpful data regarding my study and knowledge.

https://slips.de/author/veronaboatr · 2020年6月27日 上午2:40

We’re a group of volunteers and starting a new scheme in our community.

Your site offered us with helpful information to work on.
You have done a formidable activity and our entire community will be grateful to you.

www.erospoetry.net · 2020年6月27日 上午10:59

Hi there, I check your blogs on a regular basis.
Your story-telling style is witty, keep it up!

http://tinyurl.com · 2020年6月27日 上午11:06

Hello there I am so thrilled I found your weblog,
I really found you by error, while I was researching on Askjeeve for something
else, Nonetheless I am here now and would just like to say cheers for a tremendous post
and a all round interesting blog (I also love the theme/design), I don’t have time to read through it all at
the minute but I have book-marked it and also added your
RSS feeds, so when I have time I will be back to read
more, Please do keep up the superb jo.

cbd oil that works 2020 · 2020年6月27日 下午10:28

Heya i am for the first time here. I came across this board and I in finding It really useful &
it helped me out a lot. I am hoping to provide something back and
aid others like you aided me.

cbd oil that works 2020 · 2020年6月28日 上午12:54

Hi, I do think this is an excellent website. I stumbledupon it ;
) I will return yet again since i have book marked it.
Money and freedom is the greatest way to change, may you be
rich and continue to help other people.

cbd oil that works 2020 · 2020年6月28日 上午3:27

WOW just what I was looking for. Came here by searching for
cbd oil that works 2020

cbd oil that works 2020 · 2020年6月29日 上午8:25

Hi there just wanted to give you a brief heads up and let you know a few of the images aren’t loading properly.
I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same results.

发表评论

电子邮件地址不会被公开。 必填项已用*标注