Home > Web Front-end > JS Tutorial > Let's talk about how to solve the #!# problem in ngRoute path?

Let's talk about how to solve the #!# problem in ngRoute path?

青灯夜游
Release: 2021-05-11 10:34:49
forward
2539 people have browsed it

This article will introduce to you the #!# solution when the ngRoute path appears. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Let's talk about how to solve the #!# problem in ngRoute path?

Related recommendations: "angularjs tutorial"

When I was working on an open source project, I used "angular-route": "^1.6.4", I found that after setting the href of the tag, the path that appears after clicking is not #/, but #!#. However I did not set hashPrefix.

After clicking the label, the address bar will appear: http://localhost:9000/#!#about.

Print $location.

We found that the $location we set was not displayed in the path part of the pseudo URL as expected, but ran to the hash part.

The reason is: when the route version is >1.6.0, the default hashPrefix is ​​modified to ‘!’.

Equivalent to the following code

There are two solutions provided below:

1. Restore hashPrefix to the version before 1.6 That way.

2. Change the format of href

Another thing to note is that once ngRoute is introduced, the tag will seem to have the default behavior overridden by ngRoute. , once the href starts with #, it will add a / to the hash part of the URL instead of appending the string directly to #, so something like cannot jump to the id ="about" tag. I did some research and found that I can write an instruction and then call window.location.hash to solve this problem.

html

js

Note: The above define is requireJS to define a module.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of Let's talk about how to solve the #!# problem in ngRoute path?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template