Angular2在网址中没有哈希值 [英] Angular2 without hash in the url

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

问题描述

现在,我的网站的网址如下所示,因为我使用的是这里



http:// localhost:4200 /#/ cadastro



是否有可能删除网址中的散列并且不会收到404错误?



编辑:添加路由器模块

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

export const routing = RouterModule.forRoot(appRoutes);


解决方案

如果您使用 PathLocationStrategy ,如这里你可以删除URL中的哈希。



摆脱404错误需要一些服务器端的调整。一个简单快速的方法是,当请求

http:// yourhost / * 形式的URL时,将服务器配置为加载主页。

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

http://localhost:4200/#/cadastro

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

EDIT: Router Module added

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

export const routing = RouterModule.forRoot(appRoutes);

解决方案

If you use PathLocationStrategy as describe here you can remove the hash in the 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天全站免登陆