301/404 Angular中的路由* .aspx和其他URL

时间:2017-10-02 21:36:24

标签: angular http-status-code-404 angular2-routing angular-cli

我使用了angular-cli@1.2 verion和angular 2.
我已经将我的旧webform(带有aspx页面的asp.net)站点转换为角度站点,并且在我当前的webform站点托管的同一域中托管。 因此,我的所有旧页面网址都应该使用适当的重写规则重定向到我的角度网站。

我想要我的旧网站网址,其网址中可能包含* .aspx,也可能不包含* .aspx(处理301),即搜索引擎可以使用* .aspx和其他旧网址点击我的角网站。我想处理所有这些。

我已在应用程序中实现了路由规则,但在404重定向模块中面临问题。如果我试图像

那样执行未知路由

http://domainname/unknownpagehttp://domainname/asdfdfsdfhttp://domainname/loremipsum

=>它将我重定向到主页而不是404页面。

如果我可以绕过执行404模块而不是主页而不影响我当前的路由规则,我可以从那里处理旧的URL。但不幸的是,我在404中遇到了错误。

任何有Angular经验的人都可以遇到这种要求。请指导我。我是Angular 2的新手

以下是我的应用程序中的路由代码。

文件名: - app-routing.module.ts

import required files

const routes: Routes = [    

    { path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' },
    // { path: '', redirectTo: 'home', pathMatch: 'full' },
    {
        path: '',
        loadChildren: './front-end/front-end.module#FrontEndModule' ,
    },
    { path: '**', loadChildren: './not-found/not-found.module#NotFoundModule' },
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]
})

export class AppRoutingModule { }

文件名: - front-end-routing.module.ts

import required files

var childrens = [
    { path: '', loadChildren: './home/home.module#HomeModule' },
    { path: 'category', loadChildren: './category/category.module#VideosModule' },
    { path: 'product', loadChildren: './product/product.module#XpertModule' },
    { path: 'recovery', loadChildren: '../recovery/recovery.module#RecoveryModule' },
    { path: 'contactus', component: ContactusComponent },
];

const routes: Routes = [
    {
        path: '', component: FrontEndComponent,
        children: childrens
    }, {
        path: ':language', component: FrontEndComponent,
        children: childrens
    },
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})
export class FrontEndRoutingModule { }

我可以拥有类似的东西  {path:'* .aspx',redirectTo:'404'},   {path:'404',component:NotFoundComponent}

我尝试了上面的但没有工作。

我可能会错过路由规则中的某些内容。如果我这样做,请告诉我。

0 个答案:

没有答案