我正在使用asp-net core和angular 2一个web项目。我想在当前的应用程序中实现模块延迟加载的概念,但它不适用于我尝试几乎所有可用的解决方案。延迟加载模块angular 2和asp-net核心
ClientApp \程序\分量\家\ home.routing.module.ts
const routes: Routes = [
{
path: 'home', component: HomeComponent,
children: [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent }
]
}
]
export const routableComponents = [DashboardComponent]
@NgModule({
imports: [CommonModule, RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [routableComponents]
})
export class HomeRoutingModule {
}
应用路由-module.ts
const routes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'register-user', component: RegisterUserComponent },
{ path: 'home', loadChildren: "./components/home/home.routing.module#HomeRoutingModule" },
{ path: '**', redirectTo: 'login' }
我收到这与上述代码错误
EXCEPTION: Uncaught (in promise): TypeError: webpack_require.i(...) is not a function TypeError: webpack_require.i(...) is not a function
也采用这种封装按照建议here
"angular2-router-loader": "0.3.4"
webpack.config.js
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: { extensions: ['.js', '.ts'] },
output: {
filename: '[name].js',
publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{
test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader',
'angular2-router-loader']
},
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: ['to-string-loader', 'css-loader'] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
}
请建议我在做什么错。
路径的装载机到你家的路由可能需要一些帮助。这可能是我缺乏理解,但在一个项目中,我有懒惰加载我有以下...'{路径:'食谱',loadChildren:'应用程序/食谱/ recipes.module#RecipesModule'}, '注意它给出了以'app'开头的路径,而前面没有'。/'。试试吗? – Jarvis
另外一件你没有提及的是你正在运行的是哪个进程会导致你的错误。你试图建立/编译?你在做AoT吗?你只是想通过npm运行本地服务器运行或什么? –
Jarvis
用户登录到应用程序后,我想重定向到主页,我通过延迟加载,这是其中不工作的地方加载的主页 – RaviMittal