Why use tokens? How is it generated?

First, the role of navigation guard

The function is to determine whether the current route can be forwarded through judgment. This guard will be triggered automatically as long as the redirect of the route is carried out. It cannot be manually invoked to determine whether the current user is logged in (token) when processing services. If the user is logged in, the guard can jump, otherwise it will be redirected to the login page.

Second, the role of interceptors

After the page is displayed, operations cannot be performed on the page. For example, Taobao can browse home page information without login, but it will require login if clicking on commodity details and other operations. This is the interceptor, it is mainly used to intercept user requests and make corresponding processing, general judgment authority authentication, login and so on, authentication can be sent after the request.

Ps: Request authorization only

The difference between navigational guard and interceptor

So to sum up, the essential difference between a navigational guard and an interceptor is that a navigational guard looks at whether a route restriction can jump, and an interceptor looks at whether a route restriction can send a request.