aspnetcore-spa routing no provider - asp.net

I'm useing yoeman aspnetcore-spa template with angular 2.
basically, there are 3 files:
app.module.client.ts
app.module.server.ts
app.module.shared.ts
I've put my Service in the providers in app.module.client.ts then added my routing in app.module.shared.ts. Which all work and great and I could navigate to it but when I try to replace redirectTo with my new path. Which at this point is still ok but when I enter the page from localhost:5000 the console screams with error:
fail: Microsoft.AspNetCore.NodeService[0] blah bla Uncaught (in promise): Error: No provider for NameService!
and some at injectionError
if I change redirectTo: 'home' then it works and I could navigate to my page. What's worse is when I have { useHash: true } it won't stop logging errors in the terminal.
I've tried using Router to navigate to my page in HomeComponent ngOnInit() which kind of works but still has problem when i enter the page from localhost:5000. What I haven't tried is replacing HomeComponent with mine instead.
What I really want is to understand what is going on. Honestly, I'm new to this template, normally there's just one app.module.ts. There is something in this template I don't understand. Please, help!

I've figured out a work around. This template does not have the usual UniversalModule, may be that's where things went wrong. I'm not sure if it's the best way to solve it but my work around is:
adding my service in app.module.server.ts as well. This is because I was thinking the home page was first rendered on the server.
inject ORIGIN_URL in my service. I thought I might have to do similar things to app.module.client.ts and it worked. So, in the constructor of my service i've added #Inject('ORIGIN_URL') private _originUrl: string and in my http method I prefix my url with this._originUrl.

Related

Symfony 6.1 Ignoring Controller and the routes inside it

I'm converting a Symfony 3.4 site to 6.1. I created a brand new 6.1 site and am copying elements over 1-by-1. I'm using Attributes to define routes inside Controllers (no changes to routing.yaml).
I was working on some fixes in the CustomerController, when suddenly I started getting route does not exist errors for the routes inside that Controller. All other routes are working perfectly. Routes within this Controller were previously working perfectly.
I ran bin/console debug:router and sure enough, the routes inside the CustomerController are missing. However, the CustomerController.php file is still there, it has the correct permissions, as far as I can tell there are no syntax errors, but even if there were, I should be able to see the syntax errors instead of route does not exist errors, no?
As far as I can tell, Symfony is simply ignoring the existence of the CustomerController.php file. How can that be? How can I get it to include it again?
I have run bin/console cache:clear but it had no effect on this.
EDIT: I deliberately introduced a syntax error into the CustomerController.php file and refreshed the page in the browser, sure enough Symfony showed me the syntax error. I fixed the syntax error and the error went back to route does not exist - even though the route does exist in the CustomerController.php file and was previously working.
There is no further information in the log file other than the missing route exception.
EDIT2: Here's the first route and function in the Controller:
#[Route('/sales/customer', name: 'customer')]
public function index(): Response
{
return $this->render('customer/list.html.twig', [
'controller_name' => 'CustomerController',
'list' => 'customer'
]);
}
Try to fetch the links as a loop inside you template file (Twig). Something like this:
{% for post in posts %}
<a href={{ path('post_show', {'id' : post.id}) }}>
<p>Anytext here</p>
</a>
{% endfor %}
Any list will appear?
I eventually managed to reverse out the changes I had been making, and saw that I had deleted use Symfony\Component\Routing\Annotation\Route; - putting this back solved the problem! Shame that Symfony can't alert you to this kind of problem...

No match found for location with path - Vue 3 + Vue Router 4

I need to create routes dynamically within a Vue application. I have created a basic component on this code sandbox link.
The issue that I am encountering is that on first load the home page is returning a 404, even though the route has been added within the created() lifecycle of the app. I understand that the issue with this is that the navigation is triggered before app creation and therefore that is why when navigating on the app, the navigation resolves itself.
On my higher scale application, the error returned is (not showing on Sandbox because the Not Found page is defined):
[Vue Router warn]: No match found for location with path "/"
Please do not provide solutions that include adding the routes upon initialising the VueRouter because I specifically need to add them in the created() lifecycle of the app since the data I will be receiving will be from an API and I would need to handle it there.
I have tried using navigation guards but I have not managed to solve the issue as of yet.
Let me know what I am doing wrong and how I can go around solving this issue please. Any help is greatly appreciated.
Thanks in advance.
Good day to you all. :)
You need to trigger a new navigation after the route is added: https://next.router.vuejs.org/guide/advanced/dynamic-routing.html#adding-routes
i have met this problem too when i try to generate dynamic routes ,what i found is
when enter a route what i not register yet will go to this error , so you need to register a 404 page to wait our routes registered register a 404 route
hope to help u
In your /router/index.js, please add the following code after the declaration of const router:
router.addRoute('admin', { path: 'settings', component: AdminSettings })
Here you can just replace 'admin' with your own parent path;
set 'settings' as the child path;
and the component as the child component that you want.
Refresh your page then you can see the component AdminSettings with the URL like: localhost:5713/admin/settings .
Hope this helps. https://router.vuejs.org/guide/advanced/dynamic-routing.html#adding-nested-routes
I think you need store full path in local storage in router guard when page change, then get this path to redirect when app created.

Issue with Service Workers when switching from CRA to Next JS

So we recently changed our landing page from create-react-app to using Next.js. Our old create-react-app had a basic default service worker registered on users browsers.
Whenever I switched over to our new Next.js website, we realized that users who had been there before would continue to get a crappy cached version of the old website.
I've found a couple of discussions talking about this issue already, but neither solutions seem to be working for me. Those two discussions are:
A website is not refreshing because of caching of service worker, after switching from React to Next.js. How to force update?
https://www.asapdevelopers.com/service-worker-issue-nextjs-framework/
Both of these solutions essentially consist of adding a new service worker file to your Next project with some code to delete the existing service workers. That code looks like
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
navigator.serviceWorker.getRegistrations().then((registrations) => {
console.log("--");
for (let registration of registrations) {
registration.unregister().then((bool) => {
console.log("unregister: ", bool);
});
}
if (registrations.length) {
window.location.reload();
}
});
});
}
So i've tried this. My old service worker was served via a file at route OUR_URL/service-worker.js. I added a public directory to my Next project and added a file with the same name and the code above to my project. I then linked this file in my _document.js and can confirm that it runs, as well as I'm able to find it on my Next.js site. The URL for both the new and old files are identical. Unfortunately though, it looks like the issue persists.
In one of the other articles linked above, it also mentions putting this file in the root directory of your Next project. This doesn't make much sense to me as it isn't then being served in anyway that I'm aware of, but I gave this a shot as well, still with no luck.
Anyone have any idea what I might be doing wrong here, or what I could do to fix this? Essentially we just want to force remove any and all old service worker so that our new website loads correctly.
Service workers are (at least generally) registered via the site itself and not automatically found by browsers (at least not yet).
This code (unregistering all service workers for the domain) should go in whatever is being sent from next.js to the browser (e.g. index.js). If you put this on your home page all users going there should have the problem resolved. If you have reason to suspect (based on traffic data) that users have other pages bookmarked you might want to include this in a universal bundle or footer.

Is there a way in iron:router for handling "no routes configured" case?

I'd like to handle the case properly where a URL might be just slightly off (e.g. mistyped, wrong case) in my Meteor app and I'm using iron:router for routing.
How can I define my regular routes and then define some kind of "catch all" route or "no routes found" callback? Does iron:router provide such capabilities or are there easy workarounds or community packages?
I can sort of work around this by doing something like
Router.route('/:slug', ...)
last. But as soon as routes are defined not just from within the main app but also from packages I get in trouble because there's no way to say "and run this particular route last".
Thanks everybody!
Would something like this work?
this.route('notFound', {
path: '*'
});
http://www.manuel-schoebel.com/blog/iron-router-tutorial
Yeah, first of all, what you are using is an old iron:router api, check its documentation for newest routes handling.
Router handles RegEx so you can create your LAST route that catches any string.
For syntax check my earlier answer for this: Meteor infinite redirect instead of render 404

MVC3 Server Error in '/' Application

I'm not new to ASP.NET MVC but I have a really strange issue that I haven't been able to solve. I've checked most other related queries on SO and further afield but I haven't yet found a solution. I have a really simple ASP.NET MVC 3 application running under Cassini which was working fine until I added log4net logging. I've since removed all the references to log4net to try and get it back but I always get the error:
Server Error in '/' Application.
The resource cannot be found.
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed blah...
This is the result, no matter which url is requested.
The application still has the original HomeController, Index.cshtml etc and the default route from the standard 'out-of-the-box' Visual Studio 2010 template.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I've checked and double-checked that there is no file missing (e.g. a css or js file) thats required and another issue which prevents me from moving forward on this issue is that no breakpoints are hit when trying to debug it. In fact, if I put a breakpoint on the first line in the Application_Start method, and start debugging, the breakpoint is not hit at all and a second breakpoint appears (see the image below)!
This happens even if I do a clean and rebuild.
I've tried using Phil Haacks Route Debugger but still get the same error and the fact that the Application_Start breakpoint is not being hit makes me suspect my web.config. I've checked it several times and in fact replaced it with a web.config from my hosted site where the application is running ok, but still get the same result on my development setup.
I've checked there is no StartUp page in the properties.
I want to add some more functionality and be able to debug it before deploying to my hosted site but this is stopping me.
Has anyone come across breakpoints being added when you start debugging? Considering the symptoms, where would you start looking for the root of the problem?
Just solved it, so for those who might trip over this one, I've noted the reason why below. However, what might be of more value was my approach to find the issue in the face of no debugging or tracing available. As it is still a small site I decided to create another standard 'out-of-the-box' MVC 3 application and manually compare files. There appeared to be no difference between files but while going through this exercise I noticed that in the problem application, the Global.asax files were sitting in the Views folder! I must have inadvertantly moved them - it wasn't immediately obvious because the Views folder was always expanded and glancing at it, would appear that the Global.asax files were in the right place because they are normally immediately below the Views folder (just not indented as they are when inside the Views folder).
Anyway, problem caused by me but did cause some weird behaviour!

Resources