0

I'm working with Laravel (5.6) and React (16.4.1+react-router) on a project, and got into a problem maybe some of you having similar problem, so I wonder we could get some ideas. Recently I have found a solution for refreshing error (404) here: How to use React Router with Laravel? and one of the soulutions solved /app/{anything} problem, too.

Now my problem is with resource files (/css, /js) from /public folder. I tried to do a workaround with the same regex as /app =>

Route::get( '/{path?}', function() { return view( 'home' ); })->where('path', '^((?!app|api|css|js).)*$');

but it's still not working as expected. As I read, we must put this snippet after all routes we included in our app, because of Laravel's caching mechanism, but it's not working with neither /css, neither /js resource files in /public folder > but works with /api and /app routes, and anything I add before /{path?}.

Is there any solutions for this? What am I doing wrong?

Thanks for any help, LeFizzy.

1 Answer 1

0

I think I've found a solution for this, and I thought I must share this with others looking for this. First, it was by a mistake. In the home.blade.php view I linked my resource files incorrectly, like this: <link rel="stylesheet" href="http://mydomain.something/css/styles.css" /> and that's why it didn't find the route, and matched with /{path?/ - so it's actually rendered the home view rather than returning the resource file.

For this, Laravel offers a solution for this by looking for your assets in /public folder, just by linking your files simple like: <link rel="stylesheet" type="text/css" href="{{asset('css/styles.css')}}" /> and almost same solution for JS (local) assets: <script src="{{asset('js/app.js')}}" ></script>.

To mention, you should link external (from other networks) like I did with my Laravel app which didn't worked due to the problem I asked for.

Good luck with it. :)

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

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.