2

I have successfully setup my angular 2 application in asp.net core which is working great. My main.js file is inside the app folder.

Working fine beacause the default mvc templete is

 app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

working fine template

I am facing a new problem. I have use the achor tag as below. `

<li><a asp-controller="Account" asp-action="Login">Login </a></li>

Now the navigation URL is http://localhost:28739/Account/Login

In my systemjs.config.js I have mention the main as show below

 packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            },
            'angular2-in-memory-web-api': {
                main: './index.js',
                defaultExtension: 'js'
            }
        }

Its works great when there is no controller name and action name in the url. But when their is controller name and action name. It gives me a error as main.js not found. Below is the image.

error of main.js not found

Can anyone please tell me how to solve this issue.

6
  • When it works fine, have you checked the network log? What is the endpoint hit for main.js? Commented Dec 31, 2016 at 7:41
  • @chandermani - I have updated . Please have a look. Please let me know how can I resolve this issue. Commented Dec 31, 2016 at 8:45
  • You should have url rewrite setup correctly for server to work with html5 mode, with hashless urls. See if this answer helps you stackoverflow.com/questions/25730797/…. Basically your server should always resolve to same route always when using Angular Commented Dec 31, 2016 at 8:58
  • No It is not working .... Commented Dec 31, 2016 at 9:09
  • Are you using Angular router or does clicking the link load the complete page? Also have you set <base href='/'> in the <head> section? Commented Dec 31, 2016 at 9:38

2 Answers 2

0

Finally Found the solution. Here is the reference link http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/

I have added in startup.cs

routes.MapRoute(
                    name: "spa-fallback",
                    template: "{*url}",defaults: new { controller = "Home", action = "Index" });

And add <Head><base href="/" /></Head> in the layout view

Sign up to request clarification or add additional context in comments.

Comments

0

Use <base href="/" /> in your index page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.