网址中没有散列的Angular2 [英] Angular2 without hash in the url

查看:21
本文介绍了网址中没有散列的Angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我网站的 url 看起来像这样,因为我正在使用描述的方法 此处

Now, my website's url looks like this because I'm using the approach described here

http://localhost:4200/#/cadastro

是否可以删除 url 中的哈希值而不出现 404 错误?

Is it possible to remove the hash in the url and not get the 404 error?

添加路由器模块

const appRoutes: Routes = [
    { path: '', component: HomeComponent },
    { path: 'cadastro', component: CadastroNoivosComponent },
    { path: '**', component: HomeComponent }
];

export const routing = RouterModule.forRoot(appRoutes);

推荐答案

如果你使用 PathLocationStrategy 如在此处描述a> 您可以删除 URL 中的哈希值.

If you use PathLocationStrategy as describe here you can remove the hash in the URL.

但是摆脱 404 错误需要一些服务器端调整.一种快速简便的方法是配置您的服务器以在请求任何形式为 http://yourhost/* 的 URL 时加载主页.

But getting rid of 404 error needs some server side tweak. A quick and easy way is to configure your server to load the home page when any URL of the form http://yourhost/* is requested.

这篇关于网址中没有散列的Angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆