Angular 2访问视图

时间:2017-02-06 22:09:02

标签: angular

当我尝试转到benchmark of Luis Mendo时,我收到404错误。我可以通过将use hash设置为true并在url中使用hash标记来实现此功能。但是我不能这样做,因为我试图在运行时传递查询字符串参数,并且哈希标记混淆了。有没有办法在应用程序加载时使用以下URL而不使用哈希。

URL:

http://myapplication/unmanaged

路线:

import math
from math import sqrt
from math import pow

#input values
a = input('Value for a: ')
b = input('Value for b: ')
c = input('Value for c: ')

#calculate the discriminant
d = (b**2) - (4*a*c)

if d < 0:
    d *= -1
else:
    d=d

#Get two solutions
sol1 = (-b - math.sqrt(d))/(2*a)
sol2 = (-b + math.sqrt(d))/(2*a)

#print two solutions
print("El valor de x1 es:"), sol1

print("El valor de x2 es:"), sol2

1 个答案:

答案 0 :(得分:0)

当您使用与PathLocationStrategy的深层链接时,当您输入http://myapplication/unmanaged时,浏览器会尝试在服务器上找到名为unmanaged的资源。服务器上没有此类资源,因此您获得404.您需要在服务器上配置重定向,以便将未知资源重定向到您应用的index.html。然后Angular Router将解析您的URL并转到正确的观点。阅读您的服务器关于配置重定向的文档。

在URL中使用哈希,浏览器只知道哈希之后的任何内容都是用于客户端导航并且不会命中服务器。